Ejemplo n.º 1
0
 protected function _prepareTpl()
 {
     // Get the project and repository params
     $project = $this->param('project');
     $repository = $this->param('repository');
     // Get lizmapProject class
     $assign = array("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, 'measure') && $configOptions->measure == 'True') {
             $assign['measure'] = true;
         }
         $assign['locate'] = $lproj->hasLocateByLayer();
         if (property_exists($configOptions, 'print') && $configOptions->print == 'True') {
             $assign['print'] = true;
         }
         $assign['edition'] = $lproj->hasEditionLayers();
         if (property_exists($configOptions, 'geolocation') && $configOptions->geolocation == 'True') {
             $assign['geolocation'] = true;
         }
         $assign['timemanager'] = $lproj->hasTimemanagerLayers();
         $assign['attributeLayers'] = $lproj->hasAttributeLayers();
     } catch (UnknownLizmapProjectException $e) {
         jLog::logEx($e, 'error');
     }
     $this->_tpl->assign($assign);
 }
 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);
 }
 function __construct($id)
 {
     $this->formId = $id;
     $mydata = array();
     foreach (lizmap::getRepositoryList() as $repo) {
         $rep = lizmap::getRepository($repo);
         $mydata[$repo] = (string) $rep->getData('label');
     }
     $this->data = $mydata;
 }
 public function getLabel2($key, $form)
 {
     $criteria = $form->getData($this->criteriaFrom);
     if ($criteria && array_key_exists($criteria, $this->data)) {
         $p = lizmap::getProject($criteria . '~' . $key);
         if ($p) {
             return (string) $p->getData('title');
         }
     }
     return null;
 }
Ejemplo n.º 7
0
 /**
  * Redirect to the default repository project list.
  * 
  * @return Redirection to the default repository list
  */
 function index()
 {
     $rep = $this->getResponse('redirect');
     // Get repository data
     $repository = $this->param('repository');
     // Get the corresponding repository
     $lrep = lizmap::getRepository($repository);
     // Set the redirection parameters
     if ($lrep) {
         $rep->params = array('repository' => $lrep->getKey());
     }
     $rep->action = 'view~default:index';
     return $rep;
 }
 public function getLabel2($key, $form)
 {
     $criteria = $form->getData($this->criteriaFrom[0]);
     if ($criteria && array_key_exists($criteria, $this->data)) {
         try {
             $p = lizmap::getProject($criteria . '~' . $key);
             if ($p) {
                 return (string) $p->getData('title');
             }
         } catch (UnknownLizmapProjectException $e) {
             jLog::logEx($e, 'error');
             return null;
         }
     }
     return null;
 }
Ejemplo n.º 9
0
 /**
  * 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;
 }
 /**
  * Add log when needed
  * @param string $key Key of the log item to handle.
  * @param array $data Array of data to log for this item.
  *
  */
 function addLog($key, $data)
 {
     // Get log item properties
     $logItem = lizmap::getLogItem($key);
     // Optionnaly log detail
     if ($logItem->getData('logDetail')) {
         // user who modified the line
         if (!array_key_exists('user', $data)) {
             $juser = jAuth::getUserSession();
             $data['user'] = $juser->login;
         }
         // Add IP if needed
         if ($logItem->getData('logIp')) {
             $data['ip'] = $_SERVER['REMOTE_ADDR'];
         }
         // Insert log
         $logItem->insertLogDetail($data);
     }
     // Optionnaly log count
     if ($logItem->getData('logCounter')) {
         $logItem->increaseLogCounter($data['repository'], $data['project']);
     }
 }
 /**
  * Unlink child feature from their parent ( 1:n ) relation
  * by setting the foreign key to NULL
  *
  * @param string $repository Lizmap Repository
  * @param string $project Name of the project
  * @param string $layerId Child layer id.
  * @param string $pkey Child layer primary key value -> id of the line to update
  * @param string $fkey Child layer foreign key column (pointing to the parent layer primary key)
  * @return Redirect to the validation action.
  */
 function unlinkChild()
 {
     $lid = $this->param('lid');
     $fkey = $this->param('fkey');
     $pkey = $this->param('pkey');
     $pkeyval = $this->param('pkeyval');
     $project = $this->param('project');
     $repository = $this->param('repository');
     if (!$lid or !$fkey or !$pkey or !$pkeyval or !$project or !$repository) {
         jMessage::add(jLocale::get("view~edition.link.error.missing.parameter"), 'error');
         return $this->serviceAnswer();
     }
     // Get project configuration
     $lrep = lizmap::getRepository($repository);
     $lproj = lizmap::getProject($repository . '~' . $project);
     $this->project = $lproj;
     $this->repository = $lrep;
     // Get child layer information
     $layerXml = $lproj->getXmlLayer($lid);
     $layerXmlZero = $layerXml[0];
     $_layerName = $layerXmlZero->xpath('layername');
     $layerName = (string) $_layerName[0];
     $this->layerXml = $layerXml;
     // Get editLayer capabilities
     $eLayers = $lproj->getEditionLayers();
     $eLayer = $eLayers->{$layerName};
     if ($eLayer->capabilities->modifyAttribute != 'True') {
         jMessage::add('Modify feature attributes for this layer ' . $layerName . ' is not in the capabilities!', 'LayerNotEditable');
         return $this->serviceAnswer();
     }
     // Get fields data from the edition database
     $_datasource = $layerXmlZero->xpath('datasource');
     $datasource = (string) $_datasource[0];
     $s_provider = $layerXmlZero->xpath('provider');
     $this->provider = (string) $s_provider[0];
     $this->layerId = $lid;
     $this->layerName = $layerName;
     $this->getDataFields($datasource);
     // Check fields
     if (!array_key_exists($fkey, $this->dataFields) or !array_key_exists($pkey, $this->dataFields)) {
         jMessage::add('Given fields do not exists !', 'error');
         return $this->serviceAnswer();
     }
     // Build SQL
     $sql = '';
     $cnx = jDb::getConnection($this->layerId);
     $msg = false;
     $val = (int) $pkeyval;
     if ($this->dataFields[$key2]->type != 'int') {
         $val = $cnx->quote($val);
     }
     $sql = ' UPDATE ' . $this->table;
     $sql .= ' SET "' . $fkey . '" = NULL';
     $sql .= ' WHERE "' . $pkey . '" = ' . $val;
     $sql .= ';';
     // Need to break SQL ( if sqlite
     try {
         $rs = $cnx->query($sql);
         if (!$msg) {
             jMessage::add(jLocale::get('view~edition.unlink.success'), 'success');
         }
         $msg = true;
     } catch (Exception $e) {
         jLog::log("An error has been raised when modifiying data : " . $e->getMessage(), 'error');
         jLog::log("SQL = " . $sql);
         jMessage::add(jLocale::get('view~edition.unlink.error.sql'), 'error');
     }
     return $this->serviceAnswer();
 }
Ejemplo n.º 12
0
 /**
  * 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;
 }
Ejemplo n.º 13
0
 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));
 }
Ejemplo n.º 14
0
 /**
  * Query a QuickFinder database
  * @param text $query A query on OpenStreetMap object
  * @param text $bbox A bounding box in EPSG:4326 Optionnal
  * @return GeoJSON.
  */
 function get()
 {
     $rep = $this->getResponse('binary');
     $rep->outputFileName = 'search_results.json';
     $rep->mimeType = 'application/json';
     $content = '[]';
     $rep->content = $content;
     // Get project and repository, and check rights
     $project = $this->param('project');
     $repository = $this->param('repository');
     $lrep = lizmap::getRepository($repository);
     $lproj = null;
     try {
         $lproj = lizmap::getProject($repository . '~' . $project);
         if (!$lproj) {
             jMessage::add('The lizmapProject ' . strtoupper($project) . ' does not exist !', 'ProjectNotDefined');
             return $rep;
         }
     } catch (UnknownLizmapProjectException $e) {
         jLog::logEx($e, 'error');
         jMessage::add('The lizmapProject ' . strtoupper($project) . ' does not exist !', 'ProjectNotDefined');
         return $rep;
     }
     if (!$lproj->checkAcl()) {
         jMessage::add(jLocale::get('view~default.repository.access.denied'), 'AuthorizationRequired');
         return $rep;
     }
     // Parameters
     $pquery = $this->param('query');
     if (!$pquery) {
         return $rep;
     }
     $pquery = filter_var($pquery, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
     // Get FTS searches
     $ftsSearches = $lproj->hasFtsSearches();
     if (!$ftsSearches) {
         return $rep;
     }
     $searches = $ftsSearches['searches'];
     $jdb_profile = $ftsSearches['jdb_profile'];
     // Limitations
     $limit_tot = 30;
     $limit_search = 15;
     $cnx = jDb::getConnection($jdb_profile);
     // Create FTS query
     $words = explode(' ', $pquery);
     $matches = implode('* ', $words) . '*';
     $sql = "SELECT search_id,content,wkb_geom FROM quickfinder_data WHERE";
     $sql .= " content MATCH " . $cnx->quote($matches);
     // Add filter by groups and user if the user is authenticated
     if (!jAcl2::check('lizmap.tools.loginFilteredLayers.override', $lrep->getKey())) {
         $sql .= " AND ( content LIKE '%@@all' OR content NOT LIKE '%@@%'";
         $isConnected = jAuth::isConnected();
         if ($isConnected) {
             // Ok if any group matches
             $userGroups = jAcl2DbUserGroup::getGroups();
             foreach ($userGroups as $g) {
                 $sql .= " OR content LIKE '%@@" . $g . "'";
             }
             // Ok if user matches
             $user = jAuth::getUserSession();
             $login = $user->login;
             $sql .= " OR content LIKE '%@@" . $login . "'";
         }
         $sql .= ' )';
     }
     // Query and format data for each search key
     $nb = array('search' => array(), 'tot' => 0);
     $data = array();
     foreach ($searches as $skey => $sval) {
         // Add filter to get only data for given search key
         $sql_search = $sql . ' AND search_id = ' . $cnx->quote($skey);
         $limit = $limit_search;
         $sql_search .= " LIMIT " . $limit;
         //jLog::log($sql_search);
         // Run query
         $res = $cnx->query($sql_search);
         // Format data
         foreach ($res as $item) {
             $key = $item->search_id;
             if (!array_key_exists($key, $nb['search'])) {
                 $nb['search'][$key] = 0;
             }
             if ($nb['search'][$key] >= $limit_search) {
                 continue;
             }
             if ($nb['tot'] >= $limit_tot) {
                 break;
             }
             if (!array_key_exists($key, $data)) {
                 $data[$key] = array();
             }
             $data[$key]['search_name'] = $searches[$key]['search_name'];
             $data[$key]['layer_name'] = $searches[$key]['layer_name'];
             $data[$key]['srid'] = $searches[$key]['srid'];
             if (!array_key_exists('features', $data[$key])) {
                 $data[$key]['features'] = array();
             }
             $data[$key]['features'][] = array('label' => preg_replace('#@@.+#', '', $item->content), 'geometry' => $item->wkb_geom);
             $nb['search'][$key] += 1;
             $nb['tot'] += 1;
         }
     }
     $rep->content = json_encode($data);
     return $rep;
 }
Ejemplo n.º 15
0
 /**
  * Get a CSS file stored in the repository in a "media/themes" folder.
  * Url to images are replaced by getMedia URL
  *
  * @param string $repository Repository of the project.
  * @param string $project Project key.
  * @param string $path Path to the CSS file relative to the project file.
  * @return binary object The transformed CSS file.
  */
 function getCssFile()
 {
     // Get repository data
     $repository = $this->param('repository');
     $lrep = lizmap::getRepository($repository);
     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');
     // Get the file
     $path = $this->param('path');
     $repositoryPath = realpath($lrep->getPath());
     $abspath = realpath($repositoryPath . '/' . $path);
     $n_repositoryPath = str_replace('\\', '/', $repositoryPath);
     $n_abspath = str_replace('\\', '/', $abspath);
     $ok = True;
     // Only allow files within the repository for safety reasons
     // and in the media/themes/ folder
     if (!preg_match("#^" . $n_repositoryPath . "(/)?media/themes/#", $n_abspath)) {
         $ok = False;
     }
     // Check if file exists
     if ($ok and !file_exists($abspath)) {
         $ok = False;
     }
     // Check if file is CSS
     $path_parts = pathinfo($abspath);
     if (strtolower($path_parts['extension']) != 'css') {
         $ok = False;
     }
     // Redirect if errors
     if (!$ok) {
         $content = "No CSS file in the specified path";
         $rep = $this->getResponse('text');
         $rep->content = $content;
         return $rep;
     }
     // Prepare the file to return
     $rep = $this->getResponse('binary');
     $rep->doDownload = false;
     $rep->fileName = $abspath;
     // Get the name of the file
     $name = $path_parts['basename'] . '.' . $path_parts['extension'];
     $rep->outputFileName = $name;
     // Mime type
     $rep->mimeType = 'text/css';
     // Read content from file
     $content = jFile::read($abspath);
     // Replace relative images URL with getMedia URL
     $newPath = preg_replace("#" . $path_parts['basename'] . "\$#", '', $path);
     $baseUrl = jUrl::get('view~media:getMedia', array('repository' => $lrep->getKey(), 'project' => $project, 'path' => $newPath));
     $pattern = 'url\\((.+)\\)';
     $replacement = 'url(' . $baseUrl . '/\\1)';
     $content = preg_replace("#{$pattern}#", $replacement, $content);
     $content = str_replace('"', '', $content);
     $rep->content = $content;
     $rep->setExpires('+60 seconds');
     return $rep;
 }
Ejemplo n.º 16
0
 /**
  * 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();
     }
 }
Ejemplo n.º 17
0
 /**
  * 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;
 }
Ejemplo n.º 18
0
 /**
  * Get a list of log items names.
  *
  */
 public static function getLogItemList()
 {
     // read the lizmap log configuration file
     $readConfigPath = parse_ini_file(jApp::varPath() . self::$lizmapLogConfig, True);
     $logItemList = array();
     foreach ($readConfigPath as $section => $data) {
         $match = preg_match('#(^item:)#', $section, $matches);
         if (isset($matches[0])) {
             $logItemList[] = str_replace($matches[0], '', $section);
         }
     }
     self::$logItems = $logItemList;
     return self::$logItems;
 }
Ejemplo n.º 19
0
 /**
  * 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;
 }
Ejemplo n.º 20
0
 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 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;
 }
Ejemplo n.º 22
0
 /**
  *
  */
 function seeding()
 {
     $fakeServer = new jelix\FakeServerConf\ApacheMod(jApp::wwwPath(), '/index.php');
     $forced = $this->option('-f');
     $verbose = $this->option('-v');
     $rep = $this->getResponse();
     // cmdline response by default
     $project = null;
     try {
         $project = lizmap::getProject($this->param('repository') . '~' . $this->param('project'));
         // Project not found
         if (!$project) {
             $rep->addContent("The project has not be found!\n");
             return $rep;
         }
     } catch (UnknownLizmapProjectException $e) {
         $rep->addContent("The project has not be found!\n");
         return $rep;
     }
     $repository = $project->getRepository();
     $cacheId = $repository->getKey() . '_' . $project->getKey() . '_WMTS';
     $tileMatrixSetList = jCache::get($cacheId . '_tileMatrixSetList');
     if (!$tileMatrixSetList) {
         $request = new lizmapWMTSRequest($project, array('service' => 'WMTS', 'request' => 'GetCapabilities'));
         $result = $request->process();
         $tileMatrixSetList = jCache::get($cacheId . '_tileMatrixSetList');
     }
     $layers = $tileMatrixSetList = jCache::get($cacheId . '_layers');
     $layerIds = explode(',', $this->param('layers'));
     $selectedLayers = array();
     foreach ($layers as $l) {
         if (in_array('*', $layerIds) || in_array($l->name, $layerIds)) {
             $selectedLayers[] = $l;
         }
     }
     // Layer not found
     if (count($selectedLayers) == 0) {
         $rep->addContent("The layers '" . implode(',', $layerIds) . "' have not be found!\n");
         return $rep;
     }
     foreach ($selectedLayers as $layer) {
         $TileMatrixSetId = $this->param('TileMatrixSet');
         $tileMatrixSetLink = null;
         foreach ($layer->tileMatrixSetLinkList as $tms) {
             if ($tms->ref == $TileMatrixSetId) {
                 $tileMatrixSetLink = $tms;
                 break;
             }
         }
         // TileMatrixSet not found
         if (!$tileMatrixSetLink) {
             $rep->addContent("The TileMatrixSet '" . $TileMatrixSetId . "' has not be found!\n");
             continue;
         }
         $TileMatrixMin = (int) $this->param('TileMatrixMin');
         $TileMatrixMax = (int) $this->param('TileMatrixMax');
         // count tiles
         $tileCount = 0;
         foreach ($tileMatrixSetLink->tileMatrixLimits as $tileMatrixLimit) {
             if ($tileMatrixLimit->id >= $TileMatrixMin && $tileMatrixLimit->id <= $TileMatrixMax) {
                 $tmCount = ($tileMatrixLimit->maxRow - $tileMatrixLimit->minRow + 1) * ($tileMatrixLimit->maxCol - $tileMatrixLimit->minCol + 1);
                 if ($verbose) {
                     $rep->addContent($tmCount . ' tiles to generate for "' . $layer->name . '" "' . $TileMatrixSetId . '" "' . $tileMatrixLimit->id . '"' . "\n");
                 }
                 $tileCount += $tmCount;
             }
         }
         if ($verbose) {
             $rep->addContent($tileCount . ' tiles to generate for "' . $layer->name . '" "' . $TileMatrixSetId . '" between "' . $TileMatrixMin . '" and "' . $TileMatrixMax . '"' . "\n");
         }
         // generate tiles
         $rep->addContent("Start generation\n");
         $rep->addContent("================\n");
         $tileProgress = 0;
         $tileStepHeight = max(5.0, floor(5 * 100 / $tileCount));
         $tileStep = $tileStepHeight;
         foreach ($tileMatrixSetLink->tileMatrixLimits as $tileMatrixLimit) {
             if ($tileMatrixLimit->id >= $TileMatrixMin && $tileMatrixLimit->id <= $TileMatrixMax) {
                 $row = (int) $tileMatrixLimit->minRow;
                 //$rep->addContent( $tileMatrixLimit->id.' '.$tileMatrixLimit->minRow.' '.$tileMatrixLimit->maxRow.' '.$tileMatrixLimit->minCol.' '.$tileMatrixLimit->maxCol."\n");
                 while ($row <= $tileMatrixLimit->maxRow) {
                     $col = (int) $tileMatrixLimit->minCol;
                     while ($col <= $tileMatrixLimit->maxCol) {
                         $request = new lizmapWMTSRequest($project, array('service' => 'WMTS', 'version' => '1.0.0', 'request' => 'GetTile', 'layer' => $layer->name, 'format' => $layer->imageFormat, 'TileMatrixSet' => $TileMatrixSetId, 'TileMatrix' => $tileMatrixLimit->id, 'TileRow' => $row, 'TileCol' => $col));
                         if ($forced) {
                             $request->setForceRequest(True);
                         }
                         $result = $request->process();
                         //$rep->addContent($layer->name.' '.$layer->imageFormat.' '.$TileMatrixSetId.' '.$tileMatrixLimit->id.' '.$row.' '.$col.' '.$result->code."\n");
                         $col += 1;
                         $tileProgress += 1;
                         if ($verbose && $tileProgress * 100 / $tileCount >= $tileStep) {
                             $tileStep = floor($tileProgress * 100 / $tileCount);
                             $rep->addContent('Progression: ' . $tileStep . '%, ' . $tileProgress . ' tiles generated on ' . $tileCount . ' tiles' . "\n");
                             $tileStep = $tileStep + $tileStepHeight;
                         }
                     }
                     $row += 1;
                 }
             }
         }
         $rep->addContent("================\n");
         $rep->addContent("End generation\n");
     }
     return $rep;
 }
Ejemplo n.º 23
0
 function GetTile()
 {
     jClasses::inc('lizmap~lizmapWMTSRequest');
     $wmsRequest = new lizmapWMTSRequest($this->project, $this->params);
     $result = $wmsRequest->process();
     $rep = $this->getResponse('binary');
     $rep->mimeType = $result->mime;
     $rep->content = $result->data;
     $rep->doDownload = false;
     $rep->outputFileName = 'qgis_server_wmts_tile_' . $this->repository->getKey() . '_' . $this->project->getKey();
     $rep->setHttpStatus($result->code, '');
     if (!preg_match('/^image/', $result->mime)) {
         return $rep;
     }
     // HTTP browser cache expiration time
     $layername = $this->params["layer"];
     $lproj = lizmap::getProject($this->repository->getKey() . '~' . $this->project->getKey());
     $configLayers = $lproj->getLayers();
     if (property_exists($configLayers, $layername)) {
         $configLayer = $configLayers->{$layername};
         if (property_exists($configLayer, 'clientCacheExpiration')) {
             $clientCacheExpiration = (int) $configLayer->clientCacheExpiration;
             $rep->setExpires("+" . $clientCacheExpiration . " seconds");
         }
     }
     return $rep;
 }
Ejemplo n.º 24
0
 /**
  * Query a QuickFinder database
  * @param text $query A query on OpenStreetMap object
  * @param text $bbox A bounding box in EPSG:4326 Optionnal
  * @return GeoJSON.
  */
 function get()
 {
     $rep = $this->getResponse('binary');
     $rep->outputFileName = 'search_results.json';
     $rep->mimeType = 'application/json';
     $content = '[]';
     $rep->content = $content;
     // Get project and repository, and check rights
     $project = $this->param('project');
     $repository = $this->param('repository');
     $lrep = lizmap::getRepository($repository);
     $lproj = null;
     try {
         $lproj = lizmap::getProject($repository . '~' . $project);
         if (!$lproj) {
             jMessage::add('The lizmapProject ' . strtoupper($project) . ' does not exist !', 'ProjectNotDefined');
             return $rep;
         }
     } catch (UnknownLizmapProjectException $e) {
         jLog::logEx($e, 'error');
         jMessage::add('The lizmapProject ' . strtoupper($project) . ' does not exist !', 'ProjectNotDefined');
         return $rep;
     }
     if (!$lproj->checkAcl()) {
         jMessage::add(jLocale::get('view~default.repository.access.denied'), 'AuthorizationRequired');
         return $rep;
     }
     // Parameters
     $pquery = $this->param('query');
     if (!$pquery) {
         return $rep;
     }
     $pquery = filter_var($pquery, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
     // Get FTS searches
     $ftsSearches = $lproj->hasFtsSearches();
     if (!$ftsSearches) {
         return $rep;
     }
     $searches = $ftsSearches['searches'];
     $jdb_profile = $ftsSearches['jdb_profile'];
     // Limitations
     $limit_tot = 30;
     $limit_search = 10;
     // Create FTS query
     $words = explode(' ', $pquery);
     $matches = implode('* ', $words) . '*';
     $sql = "\n    SELECT search_id,content,wkb_geom\n    FROM quickfinder_data\n    WHERE content MATCH\n    ";
     $cnx = jDb::getConnection($jdb_profile);
     $sql .= " " . $cnx->quote($matches);
     $limit = max(count($searches) * $limit_search, $limit_tot);
     $sql .= " LIMIT " . $limit;
     //jLog::log($sql);
     // Run query
     $res = $cnx->query($sql);
     $data = array();
     $nb = array('search' => array(), 'tot' => 0);
     foreach ($res as $item) {
         $key = $item->search_id;
         if (!array_key_exists($key, $nb['search'])) {
             $nb['search'][$key] = 0;
         }
         if ($nb['search'][$key] >= $limit_search) {
             continue;
         }
         if ($nb['tot'] >= $limit_tot) {
             break;
         }
         if (!array_key_exists($key, $data)) {
             $data[$key] = array();
         }
         $data[$key]['search_name'] = $searches[$key]['search_name'];
         $data[$key]['layer_name'] = $searches[$key]['layer_name'];
         $data[$key]['srid'] = $searches[$key]['srid'];
         if (!array_key_exists('features', $data[$key])) {
             $data[$key]['features'] = array();
         }
         $data[$key]['features'][] = array('label' => $item->content, 'geometry' => $item->wkb_geom);
         $nb['search'][$key] += 1;
         $nb['tot'] += 1;
     }
     $rep->content = json_encode($data);
     return $rep;
 }
Ejemplo n.º 25
0
 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));
 }
Ejemplo n.º 26
0
 protected function _prepareTpl()
 {
     $protocol = jApp::coord()->request->getProtocol();
     $this->_tpl->assign('protocol', $protocol);
     $domain = jApp::coord()->request->getDomainName();
     $this->_tpl->assign('domain', $domain);
     $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();
     }
     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();
             foreach ($lprojects as $p) {
                 if (!$p->checkAcl()) {
                     continue;
                 }
                 $mrep->childItems[] = new lizmapMainViewItem($p->getData('id'), $p->getData('title'), $p->getData('abstract'), $p->getData('proj'), $p->getData('bbox'), jUrl::getFull('view~map:index', array("repository" => $p->getData('repository'), "project" => $p->getData('id'))), jUrl::getFull('view~media:illustration', array("repository" => $p->getData('repository'), "project" => $p->getData('id'))), 0, $r, 'map');
             }
             $maps[$r] = $mrep;
         }
     }
     $req = jApp::coord()->request;
     $items = jEvent::notify('mainviewGetMaps')->getResponse();
     foreach ($items as $item) {
         if ($item->parentId) {
             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) {
                     if (!preg_match('/^http/', $item->img)) {
                         $item->img = $req->getServerURI() . $item->img;
                     }
                     if (!preg_match('/^http/', $item->url)) {
                         $item->url = $req->getServerURI() . $item->url;
                     }
                     $maps[$item->parentId]->childItems[$k] = $item;
                     $replaced = true;
                 }
             }
             if (!$replaced) {
                 $maps[$item->parentId]->childItems[] = $item;
             }
         } else {
             if (isset($maps[$item->id])) {
                 $item->img = $maps[$item->id]->img;
                 $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);
 }
Ejemplo n.º 27
0
 /**
  * Empty a map service cache
  * @param string $repository Repository for which to remove all tile cache
  * @return Redirection to the index
  */
 function removeLayerCache()
 {
     // Create response to redirect to the index
     $rep = $this->getResponse("redirect");
     $rep->action = "admin~config:index";
     $repository = $this->param('repository');
     $lrep = lizmap::getRepository($repository);
     if (!$lrep) {
         jMessage::add('The repository ' . strtoupper($repository) . ' does not exist !', 'error');
         return $rep;
     }
     $project = $this->param('project');
     try {
         $lproj = lizmap::getProject($lrep->getKey() . '~' . $project);
         if (!$lproj) {
             jMessage::add('The lizmapProject ' . strtoupper($project) . ' does not exist !', 'error');
             return $rep;
         }
         $layer = $this->param('layer');
         // Remove project cache
         $lproj->clearCache();
         // Remove the cache for the layer
         lizmapProxy::clearLayerCache($repository, $project, $layer);
         jMessage::add(jLocale::get("admin~admin.cache.layer.removed", array($layer)));
         return $rep;
     } catch (UnknownLizmapProjectException $e) {
         jLog::logEx($e, 'error');
         jMessage::add('The lizmapProject ' . strtoupper($project) . ' does not exist !', 'error');
         return $rep;
     }
     return $rep;
 }
Ejemplo n.º 28
0
 /**
  * Replace a feature attribute value by its html representation
  *
  * @param string $attributeName Feature Attribute name.
  * @param string $attributeValue Feature Attribute value.
  * @param string $repository Lizmap Repository.
  * @param string $project Name of the project.
  * @param string $popupFeatureContent Content of the popup template (created by lizmap plugin) and passed several times. IF false, return only modified attribute.
  * @return string The html for the feature attribute.
  */
 public function getHtmlFeatureAttribute($attributeName, $attributeValue, $repository, $project, $popupFeatureContent = Null)
 {
     // Force $attributeValue to be a string
     $attributeName = (string) $attributeName;
     $attributeValue = (string) $attributeValue;
     if ($attributeValue == 'NULL') {
         $attributeValue = '';
     }
     // Regex to replace links, medias and images
     $urlRegex = '/(ftp|http|https):\\/\\/(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(\\/|\\/([\\w#!:.?+=&%@!\\-\\/]))?/';
     $emailRegex = '/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/';
     $imageRegex = '/\\.(jpg|jpeg|png|gif|bmp)$/i';
     $mediaRegex = '/^(\\/)?media\\//';
     $mediaTextRegex = '/\\.(txt|htm|html)$/i';
     // Remote urls and images
     if (preg_match($urlRegex, $attributeValue)) {
         if (preg_match($imageRegex, $attributeValue)) {
             $attributeValue = '<img src="' . $attributeValue . '" border="0"/>';
         } else {
             if (!$popupFeatureContent) {
                 // only if no template is passed by the user
                 $attributeValue = '<a href="' . $attributeValue . '" target="_blank">' . $attributeValue . '</a>';
             }
         }
     }
     // E-mail
     if (preg_match($emailRegex, $attributeValue)) {
         if (!$popupFeatureContent) {
             // only if no template is passed by the user
             $attributeValue = '<a href="mailto:' . $attributeValue . '"</td></tr>';
         }
     }
     // Media = file stored in the repository media folder
     if (preg_match($mediaRegex, $attributeValue)) {
         $sharps = array();
         preg_match('/(.+)#(page=[0-9]+)$/i', $attributeValue, $sharps);
         if (count($sharps) == 3) {
             $pathVal = $sharps[1];
             $sharp = $sharps[2];
         } else {
             $pathVal = $attributeValue;
             $sharp = '';
         }
         $mediaUrl = jUrl::getFull('view~media:getMedia', array('repository' => $repository, 'project' => $project, 'path' => $pathVal), 0, $_SERVER['SERVER_NAME']);
         if ($sharp) {
             $mediaUrl .= '#' . $sharp;
         }
         // Display if it is an image
         if (preg_match($imageRegex, $attributeValue)) {
             if (!$popupFeatureContent) {
                 // only if no template is passed by the user
                 $attributeValue = '<a href="' . $mediaUrl . '" target="_blank"><img src="' . $mediaUrl . '" border="0"/></a>';
             } else {
                 $attributeValue = $mediaUrl;
             }
         } else {
             if (preg_match($mediaTextRegex, $attributeValue)) {
                 $data = '';
                 // Get full path to the file
                 $lrep = lizmap::getRepository($repository);
                 $repositoryPath = realpath($lrep->getPath());
                 $abspath = realpath($repositoryPath . '/' . $attributeValue);
                 $n_repositoryPath = str_replace('\\', '/', $repositoryPath);
                 $n_abspath = str_replace('\\', '/', $abspath);
                 if (preg_match("#^" . $n_repositoryPath . "(/)?media/#", $n_abspath) and file_exists($abspath)) {
                     $data = jFile::read($abspath);
                 }
                 // Replace images src by full path
                 $iUrl = jUrl::get('view~media:getMedia', array('repository' => $repository, 'project' => $project));
                 $data = preg_replace('#src="(.+(jpg|jpeg|gif|png))"?#i', 'src="' . $iUrl . '&path=$1"', $data);
                 $attributeValue = $data;
             } else {
                 if (!$popupFeatureContent) {
                     // only if no template is passed by the user
                     $attributeValue = '<a href="' . $mediaUrl . '" target="_blank">' . $attributeValue . '</a>';
                 } else {
                     $attributeValue = $mediaUrl;
                 }
             }
         }
     } else {
         $attributeValue = preg_replace('#\\n#', '<br>', $attributeValue);
     }
     // Return the modified template or only the resulted attribute value
     if ($popupFeatureContent) {
         // Replace {$mycol} by the processed column value
         $popupFeatureContent = preg_replace('#\\{\\$' . $attributeName . '\\}#i', $attributeValue, $popupFeatureContent);
         return $popupFeatureContent;
     } else {
         // Return the modified attributeValue
         return $attributeValue;
     }
 }
Ejemplo n.º 29
0
 /**
  * Query the IGN Geoportal API
  * @param text $query A query on IGN BD adresse object
  * @param text $bbox A bounding box in EPSG:4326
  * @return XML.
  */
 function address()
 {
     $rep = $this->getResponse('json');
     $rep->data = array();
     $query = $this->param('query');
     if (!$query) {
         return $rep;
     }
     // Get the project
     $project = filter_var($this->param('project'), FILTER_SANITIZE_STRING);
     if (!$project) {
         return $rep;
     }
     // Get repository data
     $repository = $this->param('repository');
     if (!$repository) {
         return $rep;
     }
     // Get the project object
     $lproj = lizmap::getProject($repository . '~' . $project);
     if (!$lproj) {
         return $rep;
     }
     $configOptions = $lproj->getOptions();
     if (!property_exists($configOptions, 'ignKey') || $configOptions->ignKey == '') {
         return $rep;
     }
     $url = 'http://gpp3-wxs.ign.fr/' . $configOptions->ignKey . '/geoportail/ols?';
     $xls = '<XLS xmlns:xls="http://www.opengis.net/xls" xmlns:gml="http://www.opengis.net/gml" xmlns="http://www.opengis.net/xls" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.2" xsi:schemaLocation="http://www.opengis.net/xls http://schemas.opengis.net/ols/1.2/olsAll.xsd">';
     $xls .= '<RequestHeader/><Request requestID="1" version="1.2" methodName="LocationUtilityService"><GeocodeRequest returnFreeForm="false"><Address countryCode="StreetAddress">';
     $xls .= '<freeFormAddress>' . $query . '</freeFormAddress>';
     $xls .= '</Address></GeocodeRequest></Request></XLS>';
     $params = array("xls" => $xls, "output" => 'xml');
     $url .= http_build_query($params);
     $curl_handle = curl_init();
     curl_setopt($curl_handle, CURLOPT_URL, $url);
     curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array('Expect:'));
     curl_setopt($curl_handle, CURLOPT_REFERER, jUrl::getFull('lizmap~ign:address'));
     $content = curl_exec($curl_handle);
     curl_close($curl_handle);
     $rep->content = $content;
     $content = str_replace('xmlns=', 'ns=', $content);
     $content = str_replace('gml:', '', $content);
     $xml = simplexml_load_string($content);
     $results = array();
     $GeocodedAddresses = $xml->xpath('//GeocodedAddress');
     foreach ($GeocodedAddresses as $GeocodedAddress) {
         $result = array();
         $address = array();
         /*
          * bug with gml:*
          */
         $Point = $GeocodedAddress->xpath('Point/pos');
         if (count($Point) != 0) {
             $Point = $Point[0];
             $point = explode(' ', (string) $Point);
             $result['point'] = array($point[1], $point[0]);
         }
         $Address = $GeocodedAddress->xpath('Address');
         if (count($Address) == 0) {
             continue;
         }
         $Address = $Address[0];
         $Building = $Address->xpath('StreetAddress/Building');
         if (count($Building) != 0) {
             $Building = $Building[0];
             $address['number'] = (string) $Building['number'];
         }
         $Street = $Address->xpath('StreetAddress/Street');
         if (count($Street) != 0) {
             $Street = $Street[0];
             $address['street'] = (string) $Street;
         }
         $Places = $Address->xpath('Place');
         foreach ($Places as $Place) {
             $PlaceType = (string) $Place['type'];
             if ($PlaceType == 'Municipality') {
                 $address['municipality'] = (string) $Place;
             } else {
                 if ($PlaceType == 'Departement') {
                     $address['departement'] = (string) $Place;
                 } else {
                     if ($PlaceType == 'Bbox') {
                         $result['bbox'] = explode(';', (string) $Place);
                     }
                 }
             }
         }
         $formatted_address = '';
         if (array_key_exists('number', $address)) {
             $formatted_address = $address['number'] . ' ';
         }
         if (array_key_exists('street', $address) && $address['street'] != '') {
             $formatted_address .= $address['street'] . ', ';
         }
         if (array_key_exists('municipality', $address)) {
             $formatted_address .= $address['municipality'] . ', ';
         }
         if (array_key_exists('departement', $address)) {
             $formatted_address .= $address['departement'];
         }
         $result['formatted_address'] = $formatted_address;
         $results[] = $result;
     }
     $rep->data = $results;
     return $rep;
 }
 public function getProjects()
 {
     $projects = array();
     $dir = $this->getPath();
     if (is_dir($dir)) {
         if ($dh = opendir($dir)) {
             $cfgFiles = array();
             $qgsFiles = array();
             while (($file = readdir($dh)) !== false) {
                 if (substr($file, -3) == 'cfg') {
                     $cfgFiles[] = $file;
                 }
                 if (substr($file, -3) == 'qgs') {
                     $qgsFiles[] = $file;
                 }
             }
             closedir($dh);
             foreach ($qgsFiles as $qgsFile) {
                 $proj = null;
                 if (in_array($qgsFile . '.cfg', $cfgFiles)) {
                     try {
                         $proj = lizmap::getProject($this->key . '~' . substr($qgsFile, 0, -4));
                         if ($proj != null) {
                             $projects[] = $proj;
                         }
                     } catch (UnknownLizmapProjectException $e) {
                         jLog::logEx($e, 'error');
                     }
                 }
             }
         }
     }
     return $projects;
 }