diff --git a/mapBuilder/classes/listBaseLayer.class.php b/mapBuilder/classes/listBaseLayer.class.php index 702a5101..b34cc311 100644 --- a/mapBuilder/classes/listBaseLayer.class.php +++ b/mapBuilder/classes/listBaseLayer.class.php @@ -1,41 +1,39 @@ -formId = $id; - - $this->data = array( - 'osmMapnik' => 'OSM Mapnik', - 'osmStadiaMapsToner' => 'OSM StadiaMaps Toner', - 'bingStreets' => 'Bing Streets', - 'bingSatellite' => 'Bing Satellite', - 'bingHybrid' => 'Bing Hybrid', - 'ignStreets' => 'IGN Streets', - 'ignSatellite' => 'IGN Satellite', - 'ignCadastral' => 'IGN Cadastral', - 'emptyBaselayer' => jLocale::get('view~dictionnary.baselayer.empty.title') - ); - } - - public function getData($form) - { - return ($this->data); - } - - public function getLabel($key) - { - if(isset($this->data[$key])) - return $this->data[$key]; - else - return null; - } - + protected $formId = 0; + + protected $data = []; + + public function __construct($id) + { + $this->formId = $id; + + $this->data = [ + 'osmMapnik' => 'OSM Mapnik', + 'osmStadiaMapsToner' => 'OSM StadiaMaps Toner', + 'bingStreets' => 'Bing Streets', + 'bingSatellite' => 'Bing Satellite', + 'bingHybrid' => 'Bing Hybrid', + 'ignStreets' => 'IGN Streets', + 'ignSatellite' => 'IGN Satellite', + 'ignCadastral' => 'IGN Cadastral', + 'emptyBaselayer' => jLocale::get('view~dictionnary.baselayer.empty.title'), + ]; + } + + public function getData($form) + { + return $this->data; + } + + public function getLabel($key) + { + if (isset($this->data[$key])) { + return $this->data[$key]; + } + + return null; + } } -?> \ No newline at end of file diff --git a/mapBuilder/classes/listRepositories.class.php b/mapBuilder/classes/listRepositories.class.php index b5b466b5..1f3b5bf0 100644 --- a/mapBuilder/classes/listRepositories.class.php +++ b/mapBuilder/classes/listRepositories.class.php @@ -1,40 +1,38 @@ -formId = $id; + public function __construct($id) + { + $this->formId = $id; - $repositories = array(); + $repositories = []; - foreach (lizmap::getRepositoryList() as $repositoryName) { - $repository = lizmap::getRepository($repositoryName); - if( jAcl2::check('lizmap.repositories.view', $repository->getKey() )){ - $repositories[$repository->getKey()] = $repository->getData('label'); + foreach (lizmap::getRepositoryList() as $repositoryName) { + $repository = lizmap::getRepository($repositoryName); + if (jAcl2::check('lizmap.repositories.view', $repository->getKey())) { + $repositories[$repository->getKey()] = $repository->getData('label'); + } } - } - $this->data = $repositories; - } + $this->data = $repositories; + } - public function getData($form) - { - return ($this->data); - } + public function getData($form) + { + return $this->data; + } - public function getLabel($key) - { - if(isset($this->data[$key])) - return $this->data[$key]; - else - return null; - } + public function getLabel($key) + { + if (isset($this->data[$key])) { + return $this->data[$key]; + } + return null; + } } -?> \ No newline at end of file diff --git a/mapBuilder/classes/mapBuilderView.listener.php b/mapBuilder/classes/mapBuilderView.listener.php index fed7d1d8..09c1bf0b 100644 --- a/mapBuilder/classes/mapBuilderView.listener.php +++ b/mapBuilder/classes/mapBuilderView.listener.php @@ -1,10 +1,14 @@ 2.0, lizmap 3.7+ - $proj4 = new \proj4php\Proj4php(); - $sourceProj = new \proj4php\Proj('EPSG:4326', $proj4); - $destProj = new \proj4php\Proj('EPSG:3857', $proj4); + $proj4 = new proj4php\Proj4php(); + $sourceProj = new Proj('EPSG:4326', $proj4); + $destProj = new Proj('EPSG:3857', $proj4); } - $extentArraySource = explode(",", $readConfigPath['extent']); + $extentArraySource = explode(',', $readConfigPath['extent']); // Is extent valid ? - if(count($extentArraySource) == 4 && $extentArraySource === array_filter($extentArraySource, 'is_numeric')){ + if (4 == count($extentArraySource) && $extentArraySource === array_filter($extentArraySource, 'is_numeric')) { // Cast as float $extentArraySource = array_map('floatval', $extentArraySource); // Handle WGS84 bounds - if (class_exists('proj4phpPoint') ) { // lizmap 3.6 - $sourceMinPt = new \proj4phpPoint(max($extentArraySource[0], -180.0), max($extentArraySource[1], -85.06)); - $sourceMaxPt = new \proj4phpPoint(min($extentArraySource[2], 180.0), min($extentArraySource[3], 85.06)); + if (class_exists('proj4phpPoint')) { // lizmap 3.6 + $sourceMinPt = new proj4phpPoint(max($extentArraySource[0], -180.0), max($extentArraySource[1], -85.06)); + $sourceMaxPt = new proj4phpPoint(min($extentArraySource[2], 180.0), min($extentArraySource[3], 85.06)); } else { // proj4php >2.0, lizmap 3.7+ - $sourceMinPt = new \proj4php\Point(max($extentArraySource[0], -180.0), max($extentArraySource[1], -85.06)); - $sourceMaxPt = new \proj4php\Point(min($extentArraySource[2], 180.0), min($extentArraySource[3], 85.06)); + $sourceMinPt = new Point(max($extentArraySource[0], -180.0), max($extentArraySource[1], -85.06)); + $sourceMaxPt = new Point(min($extentArraySource[2], 180.0), min($extentArraySource[3], 85.06)); } - try { - $destMinPt = $proj4->transform($sourceProj,$destProj,$sourceMinPt); - $destMaxPt = $proj4->transform($sourceProj,$destProj,$sourceMaxPt); - $extent = implode(", ", array( $destMinPt->x, $destMinPt->y, $destMaxPt->x, $destMaxPt->y )); + try { + $destMinPt = $proj4->transform($sourceProj, $destProj, $sourceMinPt); + $destMaxPt = $proj4->transform($sourceProj, $destProj, $sourceMaxPt); + $extent = implode(', ', [$destMinPt->x, $destMinPt->y, $destMaxPt->x, $destMaxPt->y]); } catch (Exception $e) { // Max extent in EPSG:3857 - $extent = "-20026376.39,-20048966.10,20026376.39,20048966.10"; + $extent = '-20026376.39,-20048966.10,20026376.39,20048966.10'; } - }else{ - jMessage::add(jLocale::get("mapBuilder~default.extent.value.error"), 'error'); - $extent = jLocale::get("mapBuilder~default.extent.value.error"); + } else { + jMessage::add(jLocale::get('mapBuilder~default.extent.value.error'), 'error'); + $extent = jLocale::get('mapBuilder~default.extent.value.error'); } } - + $illustration = jApp::urlBasePath().'themes/'.jApp::config()->theme.'/css/img/250x250_mappemonde.jpg'; jClasses::inc('lizmapMainViewItem'); @@ -80,7 +85,7 @@ function onmainviewGetMaps ($event) { '_map_builder_rep', 'map' ); - $event->add( $mrep ); + $event->add($mrep); } } } diff --git a/mapBuilder/controllers/default.classic.php b/mapBuilder/controllers/default.classic.php index b72e75c7..2eecdcb1 100644 --- a/mapBuilder/controllers/default.classic.php +++ b/mapBuilder/controllers/default.classic.php @@ -1,39 +1,40 @@ getResponse('redirect'); - $rep->action = 'view~default:index'; - jMessage::add(jLocale::get('view~default.repository.access.denied'), 'error'); - return $rep; + if (!jAcl2::check('mapBuilder.access')) { + $rep = $this->getResponse('redirect'); + $rep->action = 'view~default:index'; + jMessage::add(jLocale::get('view~default.repository.access.denied'), 'error'); + + return $rep; } - $rep = $this->getResponse('html', true);// true désactive le template général + $rep = $this->getResponse('html', true); // true désactive le template général $configFile = jApp::varconfigPath('mapBuilder.ini.php'); if (!file_exists($configFile)) { $rep = $this->getResponse('basichtml', true); $rep->addContent('
MapBuilder is not configured correctly. Its configuration file is missing.
'); + return $rep; } // Get lizmap services $services = lizmap::getServices(); - $title = jLocale::get('mapBuilder~default.app.name');; + $title = jLocale::get('mapBuilder~default.app.name'); $rep->title = $title; $rep->favicon = jApp::urlBasePath().'assets/favicon/favicon.ico'; @@ -54,56 +55,56 @@ function index() { $rep->addJSLink(jApp::urlBasePath().'mapBuilder/js/bootstrap.min.js'); // Pass some configuration options to the web page through javascript var - $lizUrls = array( - "basepath" => jApp::urlBasePath(), - "config" => jUrl::get('lizmap~service:getProjectConfig'), - "wms" => jUrl::get('lizmap~service:index'), - "media" => jUrl::get('view~media:getMedia'), - "mapcontext_add" => jUrl::get('mapBuilder~mapcontext:add'), - "mapcontext_delete" => jUrl::get('mapBuilder~mapcontext:delete'), - "mapcontext_get" => jUrl::get('mapBuilder~mapcontext:get') - ); + $lizUrls = [ + 'basepath' => jApp::urlBasePath(), + 'config' => jUrl::get('lizmap~service:getProjectConfig'), + 'wms' => jUrl::get('lizmap~service:index'), + 'media' => jUrl::get('view~media:getMedia'), + 'mapcontext_add' => jUrl::get('mapBuilder~mapcontext:add'), + 'mapcontext_delete' => jUrl::get('mapBuilder~mapcontext:delete'), + 'mapcontext_get' => jUrl::get('mapBuilder~mapcontext:get'), + ]; // Load lizUrls before mapbuilder. Webpack public path needs it - $rep->addJSCode("var lizUrls = ".json_encode($lizUrls).";", true); + $rep->addJSCode('var lizUrls = '.json_encode($lizUrls).';', true); $rep->addJSLink(jApp::urlBasePath().'mapBuilder/js/mapbuilder.js'); // Read mapBuilder configuration - $readConfigPath = parse_ini_file($configFile, True); + $readConfigPath = parse_ini_file($configFile, true); // Build repository + project tree for FancyTree - $nestedTree = array(); + $nestedTree = []; - $repositoryList = array(); + $repositoryList = []; // Get selected repository from ini file if set - if(array_key_exists('repository', $readConfigPath) && !is_null(lizmap::getRepository($readConfigPath['repository']))){ + if (array_key_exists('repository', $readConfigPath) && !is_null(lizmap::getRepository($readConfigPath['repository']))) { $repositoryList[] = $readConfigPath['repository']; - }else{ + } else { $repositoryList = lizmap::getRepositoryList(); } foreach ($repositoryList as $repositoryName) { $repository = lizmap::getRepository($repositoryName); - if( jAcl2::check('lizmap.repositories.view', $repository->getKey() )){ + if (jAcl2::check('lizmap.repositories.view', $repository->getKey())) { $projects = $repository->getProjects(); - $projectArray = array(); + $projectArray = []; foreach ($projects as $project) { $projectArray[] = [ - "title" => $project->getData('title'), // deprecated, use getTitle() for lizmap >=3.5 - "folder" => true, - "lazy" => true, - "repository" => $repositoryName, - "project" => $project->getKey() + 'title' => $project->getData('title'), // deprecated, use getTitle() for lizmap >=3.5 + 'folder' => true, + 'lazy' => true, + 'repository' => $repositoryName, + 'project' => $project->getKey(), ]; } $nestedTree[] = [ - "title" => $repository->getData('label'), // deprecated, use getLabel() for lizmap >=3.5 - "folder" => true, - "children" => $projectArray + 'title' => $repository->getData('label'), // deprecated, use getLabel() for lizmap >=3.5 + 'folder' => true, + 'children' => $projectArray, ]; } } @@ -112,11 +113,11 @@ function index() { $rep->addJSCode('var mapBuilder = {"layerStoreTree": '.json_encode($nestedTree).'};'); // Get original extent from ini file if set - if(array_key_exists('extent', $readConfigPath)){ - $rep->addJSCode("mapBuilder.extent = [".$readConfigPath['extent']."];"); + if (array_key_exists('extent', $readConfigPath)) { + $rep->addJSCode('mapBuilder.extent = ['.$readConfigPath['extent'].'];'); } // Get base layer from ini file if set - if(array_key_exists('baseLayer', $readConfigPath)){ + if (array_key_exists('baseLayer', $readConfigPath)) { $rep->addJSCode("mapBuilder.baseLayer = '".$readConfigPath['baseLayer']."';"); jClasses::inc('mapBuilder~listBaseLayer'); @@ -125,7 +126,7 @@ function index() { $userListBaseLayer = explode(',', $readConfigPath['baseLayer']); foreach ($listBaseLayer as $key => $value) { - if(!in_array($key, $userListBaseLayer)){ + if (!in_array($key, $userListBaseLayer)) { unset($listBaseLayer[$key]); } } @@ -133,43 +134,45 @@ function index() { $rep->body->assign('baseLayer', $listBaseLayer); } // Get default base layer from ini file if set - if(array_key_exists('baseLayerDefault', $readConfigPath)){ + if (array_key_exists('baseLayerDefault', $readConfigPath)) { $rep->body->assign('baseLayerDefault', $readConfigPath['baseLayerDefault']); } // Get base layer key from ini file if set - if(array_key_exists('baseLayerKeyOSMCycleMap', $readConfigPath)){ + if (array_key_exists('baseLayerKeyOSMCycleMap', $readConfigPath)) { $rep->addJSCode("mapBuilder.baseLayerKeyOSMCycleMap = '".$readConfigPath['baseLayerKeyOSMCycleMap']."';"); } // Get base layer key from ini file if set - if(array_key_exists('baseLayerKeyBing', $readConfigPath)){ + if (array_key_exists('baseLayerKeyBing', $readConfigPath)) { $rep->addJSCode("mapBuilder.baseLayerKeyBing = '".$readConfigPath['baseLayerKeyBing']."';"); } // Get base layer key from ini file if set - if(array_key_exists('baseLayerKeyIGN', $readConfigPath)){ + if (array_key_exists('baseLayerKeyIGN', $readConfigPath)) { $rep->addJSCode("mapBuilder.baseLayerKeyIGN = '".$readConfigPath['baseLayerKeyIGN']."';"); } // Get attributeTableTool key from ini file if set - if(array_key_exists('attributeTableTool', $readConfigPath)){ + if (array_key_exists('attributeTableTool', $readConfigPath)) { $rep->body->assign('attributeTableTool', $readConfigPath['attributeTableTool']); } // Get locales $lang = $this->param('lang'); - if(!$lang) - $lang = jLocale::getCurrentLang().'_'.jLocale::getCurrentCountry(); + if (!$lang) { + $lang = jLocale::getCurrentLang().'_'.jLocale::getCurrentCountry(); + } - $data = array(); + $data = []; $path = jApp::getModulePath('mapBuilder').'locales/en_US/dictionary.UTF-8.properties'; - if(file_exists($path)){ - $lines = file($path); - foreach ($lines as $lineNumber => $lineContent){ - if(!empty($lineContent) and $lineContent != '\n'){ - $exp = explode('=', trim($lineContent)); - if(!empty($exp[0])) - $data[$exp[0]] = jLocale::get('mapBuilder~dictionary.'.$exp[0], null, $lang); + if (file_exists($path)) { + $lines = file($path); + foreach ($lines as $lineNumber => $lineContent) { + if (!empty($lineContent) and '\n' != $lineContent) { + $exp = explode('=', trim($lineContent)); + if (!empty($exp[0])) { + $data[$exp[0]] = jLocale::get('mapBuilder~dictionary.'.$exp[0], null, $lang); + } + } } - } } $rep->addJSCode('var lizDict = '.json_encode($data).';'); @@ -179,7 +182,7 @@ function index() { $rep->body->assign('allowUserAccountRequests', $services->allowUserAccountRequests); // Add Google Analytics ID - if($services->googleAnalyticsID != '' && preg_match("/^UA-\d+-\d+$/", $services->googleAnalyticsID) == 1 ) { + if ('' != $services->googleAnalyticsID && 1 == preg_match('/^UA-\\d+-\\d+$/', $services->googleAnalyticsID)) { $rep->body->assign('googleAnalyticsID', $services->googleAnalyticsID); } @@ -189,9 +192,9 @@ function index() { $rep->body->assignZone('LIST_MAPCONTEXT', 'list_mapcontext'); // Override default theme with color set in admin panel - if($cssContent = jFile::read(jApp::varPath('lizmap-theme-config/') . 'theme.css') ){ - $css = ''; - $rep->addHeadContent($css); + if ($cssContent = jFile::read(jApp::varPath('lizmap-theme-config/').'theme.css')) { + $css = ''; + $rep->addHeadContent($css); } return $rep; diff --git a/mapBuilder/controllers/mapcontext.classic.php b/mapBuilder/controllers/mapcontext.classic.php index afabe9f1..63bb56b3 100644 --- a/mapBuilder/controllers/mapcontext.classic.php +++ b/mapBuilder/controllers/mapcontext.classic.php @@ -1,32 +1,30 @@ getResponse('htmlfragment'); // Make sure that it is a POST request. - if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){ + if (0 != strcasecmp($_SERVER['REQUEST_METHOD'], 'POST')) { throw new Exception('Request method must be POST!'); } // Check name - $name = filter_var( $this->param('name'), FILTER_SANITIZE_STRING ); - if( empty($name) ){ + $name = filter_var($this->param('name'), FILTER_SANITIZE_STRING); + if (empty($name)) { jMessage::add('Please give a name', 'error'); - }else{ + } else { $dao = jDao::get('mapBuilder~mapcontext'); $record = jDao::createRecord('mapBuilder~mapcontext'); @@ -36,36 +34,35 @@ function add() { // Access control $record->is_public = false; - if(jAcl2::check('mapBuilder.mapcontext.public.manage')){ + if (jAcl2::check('mapBuilder.mapcontext.public.manage')) { $record->is_public = $this->param('is_public'); } $record->mapcontext = $this->param('mapcontext'); // Save the new mapcontext - $id = Null; - try{ + $id = null; + + try { $id = $dao->insert($record); - }catch(Exception $e){ - jLog::log( 'Error while inserting the mapcontext'); - jLog::log( $e->getMessage()); - jMessage::add( 'Error while inserting the mapcontext', 'error' ); + } catch (Exception $e) { + jLog::log('Error while inserting the mapcontext'); + jLog::log($e->getMessage()); + jMessage::add('Error while inserting the mapcontext', 'error'); } } $rep->addContent(jZone::get('list_mapcontext')); + return $rep; } - /* - * Delete mapcontext by id - * - */ - function delete(){ - + // Delete mapcontext by id + public function delete() + { $rep = $this->getResponse('htmlfragment'); // Make sure that it is a POST request. - if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){ + if (0 != strcasecmp($_SERVER['REQUEST_METHOD'], 'POST')) { throw new Exception('Request method must be POST!'); } @@ -79,19 +76,19 @@ function delete(){ // Conditions to get the mapcontext $daomc = jDao::get('mapBuilder~mapcontext'); $conditions = jDao::createConditions(); - $conditions->addCondition('login','=',$usr_login); - $conditions->addCondition('id','=',$id); + $conditions->addCondition('login', '=', $usr_login); + $conditions->addCondition('id', '=', $id); $mcCount = $daomc->countBy($conditions); - if( $mcCount != 1 ){ + if (1 != $mcCount) { jMessage::add('You can\'t delete this map context or it doesn\'t exist', 'error'); - }else{ - try{ + } else { + try { $daomc->delete($id); - }catch(Exception $e){ - jLog::log( 'Error while deleting the mapcontext'); - jLog::log( $e->getMessage()); - jMessage::add( 'Error while deleting the mapcontext', 'error' ); + } catch (Exception $e) { + jLog::log('Error while deleting the mapcontext'); + jLog::log($e->getMessage()); + jMessage::add('Error while deleting the mapcontext', 'error'); } } @@ -100,12 +97,9 @@ function delete(){ return $rep; } - /* - * Get mapcontext by id - * - */ - function get(){ - + // Get mapcontext by id + public function get() + { // Get user $juser = jAuth::getUserSession(); $usr_login = $juser->login; @@ -116,27 +110,27 @@ function get(){ // Conditions to get the bookmark $daomc = jDao::get('mapBuilder~mapcontext'); $conditions = jDao::createConditions(); - $conditions->addCondition('id','=',$id); + $conditions->addCondition('id', '=', $id); // Get map context if saved by logged user or public ones $conditions->startGroup('OR'); - $conditions->addCondition('login','=',$usr_login); - $conditions->addCondition('is_public','=',true); + $conditions->addCondition('login', '=', $usr_login); + $conditions->addCondition('is_public', '=', true); $conditions->endGroup(); $mcCount = $daomc->countBy($conditions); - if( $mcCount != 1 ){ - jMessage::add('You don\'t have access to this map context or it doesn\'t exist' , 'error'); + if (1 != $mcCount) { + jMessage::add('You don\'t have access to this map context or it doesn\'t exist', 'error'); + return $this->error(); - }else{ - $mcList = $daomc->findBy($conditions); - $mcParams = array(); - foreach( $mcList as $mc ){ - $mcParams = json_decode(htmlspecialchars_decode($mc->mapcontext,ENT_QUOTES )); - } - $rep = $this->getResponse('json'); - $rep->data = $mcParams; - return $rep; } - } + $mcList = $daomc->findBy($conditions); + $mcParams = []; + foreach ($mcList as $mc) { + $mcParams = json_decode(htmlspecialchars_decode($mc->mapcontext, ENT_QUOTES)); + } + $rep = $this->getResponse('json'); + $rep->data = $mcParams; + return $rep; + } } diff --git a/mapBuilder/install/conf/mapBuilder.ini.php b/mapBuilder/install/conf/mapBuilder.ini.php index e360142b..09ad3b22 100644 --- a/mapBuilder/install/conf/mapBuilder.ini.php +++ b/mapBuilder/install/conf/mapBuilder.ini.php @@ -1,4 +1,4 @@ -; +; ;for security reasons , don't remove or modify the first line ;; if you want the map builder to display only one repository, put its id here. Leave blank to get all repositories. diff --git a/mapBuilder/install/configure.php b/mapBuilder/install/configure.php index b2a37f29..5becd2af 100644 --- a/mapBuilder/install/configure.php +++ b/mapBuilder/install/configure.php @@ -1,28 +1,30 @@ copyDirectoryContent('../www/css', \jApp::wwwPath('mapBuilder/css')); - $helpers->copyDirectoryContent('../www/js/dist', \jApp::wwwPath('mapBuilder/js')); + $helpers->copyDirectoryContent('../www/css', jApp::wwwPath('mapBuilder/css')); + $helpers->copyDirectoryContent('../www/js/dist', jApp::wwwPath('mapBuilder/js')); } } diff --git a/mapBuilder/install/install.php b/mapBuilder/install/install.php index b5547ff3..e447deb9 100644 --- a/mapBuilder/install/install.php +++ b/mapBuilder/install/install.php @@ -1,22 +1,26 @@ copyDirectoryContent('conf', \jApp::varconfigPath()); + $helpers->copyDirectoryContent('conf', jApp::varconfigPath()); // Add mapcontext table $helpers->database()->useDbProfile('jauth'); diff --git a/mapBuilder/install/install_1_6.php b/mapBuilder/install/install_1_6.php index 8ece2eea..db1537bb 100644 --- a/mapBuilder/install/install_1_6.php +++ b/mapBuilder/install/install_1_6.php @@ -1,19 +1,21 @@ copyDirectoryContent('../www/css', jApp::wwwPath('mapBuilder/css')); $this->copyDirectoryContent('../www/js/dist', jApp::wwwPath('mapBuilder/js')); @@ -29,15 +31,15 @@ function install() { } // Set ACL - if ($this->firstExec('acl2') ) { + if ($this->firstExec('acl2')) { $this->useDbProfile('auth'); // Add rights group - jAcl2DbManager::addSubjectGroup ('mapBuilder.subject.group', 'mapBuilder~default.acl.subject.group.name'); + jAcl2DbManager::addSubjectGroup('mapBuilder.subject.group', 'mapBuilder~default.acl.subject.group.name'); // Add right subject - jAcl2DbManager::addSubject( 'mapBuilder.access', 'mapBuilder~default.acl.subject.access.name', 'mapBuilder.subject.group'); - jAcl2DbManager::addSubject( 'mapBuilder.mapcontext.public.manage', 'mapBuilder~default.acl.subject.mapcontext.public.manage', 'mapBuilder.subject.group'); + jAcl2DbManager::addSubject('mapBuilder.access', 'mapBuilder~default.acl.subject.access.name', 'mapBuilder.subject.group'); + jAcl2DbManager::addSubject('mapBuilder.mapcontext.public.manage', 'mapBuilder~default.acl.subject.mapcontext.public.manage', 'mapBuilder.subject.group'); // Add rights on group admins jAcl2DbManager::addRight('admins', 'mapBuilder.access'); diff --git a/mapBuilder/install/upgrade.php b/mapBuilder/install/upgrade.php index 64a0acc7..70f72545 100644 --- a/mapBuilder/install/upgrade.php +++ b/mapBuilder/install/upgrade.php @@ -1,16 +1,20 @@ copyDirectoryContent('../www/css', jApp::wwwPath('mapBuilder/css'), true); $helpers->copyDirectoryContent('../www/js/dist', jApp::wwwPath('mapBuilder/js'), true); diff --git a/mapBuilder/install/upgrade_acl.php b/mapBuilder/install/upgrade_acl.php index 4c8b497a..1dcc1559 100644 --- a/mapBuilder/install/upgrade_acl.php +++ b/mapBuilder/install/upgrade_acl.php @@ -1,30 +1,31 @@ firstExec('acl2') ) { + public function install() + { + if ($this->firstExec('acl2')) { $this->useDbProfile('auth'); // Add rights group - jAcl2DbManager::addSubjectGroup ('mapBuilder.subject.group', 'mapBuilder~default.acl.subject.group.name'); + jAcl2DbManager::addSubjectGroup('mapBuilder.subject.group', 'mapBuilder~default.acl.subject.group.name'); // Add right subject - jAcl2DbManager::addSubject( 'mapBuilder.access', 'mapBuilder~default.acl.subject.access.name', 'mapBuilder.subject.group'); - jAcl2DbManager::addSubject( 'mapBuilder.mapcontext.public.manage', 'mapBuilder~default.acl.subject.mapcontext.public.manage', 'mapBuilder.subject.group'); + jAcl2DbManager::addSubject('mapBuilder.access', 'mapBuilder~default.acl.subject.access.name', 'mapBuilder.subject.group'); + jAcl2DbManager::addSubject('mapBuilder.mapcontext.public.manage', 'mapBuilder~default.acl.subject.mapcontext.public.manage', 'mapBuilder.subject.group'); // Add rights on group admins jAcl2DbManager::addRight('admins', 'mapBuilder.access'); diff --git a/mapBuilder/install/upgrade_createtable.php b/mapBuilder/install/upgrade_createtable.php index b84ce0ce..3ce8a3c0 100644 --- a/mapBuilder/install/upgrade_createtable.php +++ b/mapBuilder/install/upgrade_createtable.php @@ -1,23 +1,24 @@ firstDbExec() ) { + if ($this->firstDbExec()) { $this->useDbProfile('jauth'); $this->execSQLScript('sql/mapcontext'); } diff --git a/mapBuilder/install/upgrade_toggleattributetable.php b/mapBuilder/install/upgrade_toggleattributetable.php index 52ab55ff..f44e3822 100644 --- a/mapBuilder/install/upgrade_toggleattributetable.php +++ b/mapBuilder/install/upgrade_toggleattributetable.php @@ -1,21 +1,22 @@ setValue('attributeTableTool', 'true'); diff --git a/mapBuilder/zones/list_mapcontext.zone.php b/mapBuilder/zones/list_mapcontext.zone.php index c6d529b8..a4dcd5c6 100644 --- a/mapBuilder/zones/list_mapcontext.zone.php +++ b/mapBuilder/zones/list_mapcontext.zone.php @@ -1,52 +1,54 @@ login; - $loggedUser = false; - - // Get user mapcontexts - if($usr_login){ - $loggedUser = true; - - $daomc = jDao::get('mapBuilder~mapcontext'); - $conditions = jDao::createConditions(); - $conditions->addCondition('login','=',$usr_login); - $mcOwnList = $daomc->findBy($conditions); - $mcOwnCount = $daomc->countBy($conditions); - - $this->_tpl->assign('mcOwnList',$mcOwnList); - $this->_tpl->assign('mcOwnCount',$mcOwnCount); - } - - // Get public mapcontexts - $daomc = jDao::get('mapBuilder~mapcontext'); - $conditions = jDao::createConditions(); - // Don't display logged user map context twice - if($usr_login){ - $conditions->addCondition('login','!=',$usr_login); - } - $conditions->addCondition('is_public','=',true); - $mcSharedList = $daomc->findBy($conditions); - $mcSharedCount = $daomc->countBy($conditions); - - // Get html content - $this->_tpl->assign('loggedUser',$loggedUser); - $this->_tpl->assign('mcSharedList',$mcSharedList); - $this->_tpl->assign('mcSharedCount',$mcSharedCount); - } +class list_mapcontextZone extends jZone +{ + protected $_tplname = 'list_mapcontext'; + + protected function _prepareTpl() + { + // Get user + $juser = jAuth::getUserSession(); + $usr_login = $juser->login; + $loggedUser = false; + + // Get user mapcontexts + if ($usr_login) { + $loggedUser = true; + + $daomc = jDao::get('mapBuilder~mapcontext'); + $conditions = jDao::createConditions(); + $conditions->addCondition('login', '=', $usr_login); + $mcOwnList = $daomc->findBy($conditions); + $mcOwnCount = $daomc->countBy($conditions); + + $this->_tpl->assign('mcOwnList', $mcOwnList); + $this->_tpl->assign('mcOwnCount', $mcOwnCount); + } + + // Get public mapcontexts + $daomc = jDao::get('mapBuilder~mapcontext'); + $conditions = jDao::createConditions(); + // Don't display logged user map context twice + if ($usr_login) { + $conditions->addCondition('login', '!=', $usr_login); + } + $conditions->addCondition('is_public', '=', true); + $mcSharedList = $daomc->findBy($conditions); + $mcSharedCount = $daomc->countBy($conditions); + + // Get html content + $this->_tpl->assign('loggedUser', $loggedUser); + $this->_tpl->assign('mcSharedList', $mcSharedList); + $this->_tpl->assign('mcSharedCount', $mcSharedCount); + } } diff --git a/mapBuilderAdmin/classes/mapBuilderAdminConfig.listener.php b/mapBuilderAdmin/classes/mapBuilderAdminConfig.listener.php index f9db9ccf..09a108e4 100644 --- a/mapBuilderAdmin/classes/mapBuilderAdminConfig.listener.php +++ b/mapBuilderAdmin/classes/mapBuilderAdminConfig.listener.php @@ -1,21 +1,23 @@ childItems[] = new masterAdminMenuItem( + 'mapBuilderAdmin_configuration', + jLocale::get('mapBuilderAdmin~admin.menu.configuration.label'), + jUrl::get('mapBuilderAdmin~config:index'), + 122 + ); - // Child for the configuration of mapBuilder - $bloc->childItems[] = new masterAdminMenuItem( - 'mapBuilderAdmin_configuration', - jLocale::get("mapBuilderAdmin~admin.menu.configuration.label"), - jUrl::get('mapBuilderAdmin~config:index'), 122 - ); - - // Add the bloc - $event->add($bloc); + // Add the bloc + $event->add($bloc); + } } - } } diff --git a/mapBuilderAdmin/controllers/config.classic.php b/mapBuilderAdmin/controllers/config.classic.php index 98e9576f..7e922c2c 100644 --- a/mapBuilderAdmin/controllers/config.classic.php +++ b/mapBuilderAdmin/controllers/config.classic.php @@ -1,178 +1,196 @@ array( 'jacl2.right'=>'mapBuilder.access'), - 'modify' => array( 'jacl2.right'=>'lizmap.admin.services.update'), - 'edit' => array( 'jacl2.right'=>'lizmap.admin.services.update'), - 'save' => array( 'jacl2.right'=>'lizmap.admin.services.update'), - 'validate' => array( 'jacl2.right'=>'lizmap.admin.services.update') - ); - - private $ini = null; - - function __construct( $request ) { - parent::__construct( $request ); + * mapBuilder administration. + * + * @author 3liz + * @copyright 2019-2020 3liz + * + * @see https://3liz.com + * + * @license Mozilla Public License : http://www.mozilla.org/MPL/ + */ +class configCtrl extends jController +{ + // Configure access via jacl2 rights management + public $pluginParams = [ + '*' => ['jacl2.right' => 'mapBuilder.access'], + 'modify' => ['jacl2.right' => 'lizmap.admin.services.update'], + 'edit' => ['jacl2.right' => 'lizmap.admin.services.update'], + 'save' => ['jacl2.right' => 'lizmap.admin.services.update'], + 'validate' => ['jacl2.right' => 'lizmap.admin.services.update'], + ]; + + private $ini; + + public function __construct($request) + { + parent::__construct($request); $monfichier = jApp::varconfigPath('mapBuilder.ini.php'); - $this->ini = new \Jelix\IniFile\IniModifier($monfichier); + $this->ini = new IniModifier($monfichier); } - /** - * mapBuilder administration - */ - function index() { - $rep = $this->getResponse('html'); - - // Create the form - $form = jForms::create('mapBuilderAdmin~config'); - - // Set form data values - foreach ( $form->getControls() as $ctrl ) { - if ( $ctrl->type != 'submit' ){ - $val = $this->ini->getValue( $ctrl->ref); - if( $ctrl->ref == 'baseLayer' ){ - $val = explode(',', $val); + /** + * mapBuilder administration. + */ + public function index() + { + $rep = $this->getResponse('html'); + + // Create the form + $form = jForms::create('mapBuilderAdmin~config'); + + // Set form data values + foreach ($form->getControls() as $ctrl) { + if ('submit' != $ctrl->type) { + $val = $this->ini->getValue($ctrl->ref); + if ('baseLayer' == $ctrl->ref) { + $val = explode(',', $val); + } + $form->setData($ctrl->ref, $val); + } } - $form->setData( $ctrl->ref, $val ); - } + + $tpl = new jTpl(); + $tpl->assign('form', $form); + $rep->body->assign('MAIN', $tpl->fetch('config_view')); + + return $rep; } - $tpl = new jTpl(); - $tpl->assign( 'form', $form ); - $rep->body->assign('MAIN', $tpl->fetch('config_view')); - - return $rep; - } - - /** - * Modification of the configuration. - * @return Redirect to the form display action. - */ - public function modify(){ - // Create the form - $form = jForms::create('mapBuilderAdmin~config'); - - // Set form data values - foreach ( $form->getControls() as $ctrl ) { - if ( $ctrl->type != 'submit' ){ - $val = $this->ini->getValue( $ctrl->ref); - if( $ctrl->ref == 'baseLayer' ){ - $val = explode(',', $val); - } - $form->setData( $ctrl->ref, $val ); + /** + * Modification of the configuration. + * + * @return Redirect to the form display action + */ + public function modify() + { + // Create the form + $form = jForms::create('mapBuilderAdmin~config'); + + // Set form data values + foreach ($form->getControls() as $ctrl) { + if ('submit' != $ctrl->type) { + $val = $this->ini->getValue($ctrl->ref); + if ('baseLayer' == $ctrl->ref) { + $val = explode(',', $val); + } + $form->setData($ctrl->ref, $val); + } } - } - // redirect to the form display action - $rep= $this->getResponse("redirect"); - $rep->action="mapBuilderAdmin~config:edit"; - return $rep; - } - - /** - * Display the form to modify the config. - * @return Display the form. - */ - public function edit(){ - $rep = $this->getResponse('html'); - - // Get the form - $form = jForms::get('mapBuilderAdmin~config'); - - if ( !$form ) { - // redirect to default page - jMessage::add('error in edit'); - $rep = $this->getResponse('redirect'); - $rep->action ='mapBuilderAdmin~config:index'; - return $rep; - } - // Display form - $tpl = new jTpl(); - $tpl->assign('form', $form); - $rep->body->assign('MAIN', $tpl->fetch('mapBuilderAdmin~config_edit')); - return $rep; - } - - /** - * Save the data for the config. - * @return Redirect to the index. - */ - function save(){ - $form = jForms::get('mapBuilderAdmin~config'); - - // token - $token = $this->param('__JFORMS_TOKEN__'); - if( !$token ){ - // redirection vers la page d'erreur - $rep= $this->getResponse("redirect"); - $rep->action="mapBuilderAdmin~config:index"; - return $rep; - } + // redirect to the form display action + $rep = $this->getResponse('redirect'); + $rep->action = 'mapBuilderAdmin~config:edit'; - // If the form is not defined, redirection - if( !$form ){ - $rep= $this->getResponse("redirect"); - $rep->action="mapBuilderAdmin~config:index"; - return $rep; + return $rep; } - // Set the other form data from the request data - $form->initFromRequest(); + /** + * Display the form to modify the config. + * + * @return Display the form + */ + public function edit() + { + $rep = $this->getResponse('html'); + + // Get the form + $form = jForms::get('mapBuilderAdmin~config'); + + if (!$form) { + // redirect to default page + jMessage::add('error in edit'); + $rep = $this->getResponse('redirect'); + $rep->action = 'mapBuilderAdmin~config:index'; + + return $rep; + } + // Display form + $tpl = new jTpl(); + $tpl->assign('form', $form); + $rep->body->assign('MAIN', $tpl->fetch('mapBuilderAdmin~config_edit')); - // Check the form - if ( !$form->check() ) { - // Errors : redirection to the display action - $rep = $this->getResponse('redirect'); - $rep->action='mapBuilderAdmin~config:edit'; - $rep->params['errors']= "1"; - return $rep; + return $rep; } - // Save the data - foreach ( $form->getControls() as $ctrl ) { - if ( $ctrl->type != 'submit' ){ - $val = $form->getData( $ctrl->ref ); - if( $ctrl->ref == 'baseLayer' ){ - $val = implode(',', $val); + /** + * Save the data for the config. + * + * @return Redirect to the index + */ + public function save() + { + $form = jForms::get('mapBuilderAdmin~config'); + + // token + $token = $this->param('__JFORMS_TOKEN__'); + if (!$token) { + // redirection vers la page d'erreur + $rep = $this->getResponse('redirect'); + $rep->action = 'mapBuilderAdmin~config:index'; + + return $rep; } - $this->ini->setValue( $ctrl->ref, $val); - } - } - $this->ini->save(); - // Redirect to the validation page - $rep= $this->getResponse("redirect"); - $rep->action="mapBuilderAdmin~config:validate"; + // If the form is not defined, redirection + if (!$form) { + $rep = $this->getResponse('redirect'); + $rep->action = 'mapBuilderAdmin~config:index'; - return $rep; - } + return $rep; + } - /** - * Validate the data for the config : destroy form and redirect. - * @return Redirect to the index. - */ - function validate(){ + // Set the other form data from the request data + $form->initFromRequest(); - // Destroy the form - if($form = jForms::get('mapBuilderAdmin~config')){ - jForms::destroy('mapBuilderAdmin~config'); + // Check the form + if (!$form->check()) { + // Errors : redirection to the display action + $rep = $this->getResponse('redirect'); + $rep->action = 'mapBuilderAdmin~config:edit'; + $rep->params['errors'] = '1'; + + return $rep; + } + + // Save the data + foreach ($form->getControls() as $ctrl) { + if ('submit' != $ctrl->type) { + $val = $form->getData($ctrl->ref); + if ('baseLayer' == $ctrl->ref) { + $val = implode(',', $val); + } + $this->ini->setValue($ctrl->ref, $val); + } + } + $this->ini->save(); + + // Redirect to the validation page + $rep = $this->getResponse('redirect'); + $rep->action = 'mapBuilderAdmin~config:validate'; + + return $rep; } - // Redirect to the index - $rep= $this->getResponse("redirect"); - $rep->action="mapBuilderAdmin~config:index"; + /** + * Validate the data for the config : destroy form and redirect. + * + * @return Redirect to the index + */ + public function validate() + { + // Destroy the form + if ($form = jForms::get('mapBuilderAdmin~config')) { + jForms::destroy('mapBuilderAdmin~config'); + } + + // Redirect to the index + $rep = $this->getResponse('redirect'); + $rep->action = 'mapBuilderAdmin~config:index'; - return $rep; - } + return $rep; + } } diff --git a/mapBuilderAdmin/controllers/default.classic.php b/mapBuilderAdmin/controllers/default.classic.php index 9ca40ee0..c185bb9e 100644 --- a/mapBuilderAdmin/controllers/default.classic.php +++ b/mapBuilderAdmin/controllers/default.classic.php @@ -1,21 +1,17 @@ getResponse('html'); - return $rep; +/** + * @author your name + * @copyright 2018-2020 3liz + * + * @see http://3liz.com + * + * @license Mozilla Public License : http://www.mozilla.org/MPL/ + */ +class defaultCtrl extends jController +{ + public function index() + { + return $this->getResponse('html'); } } - diff --git a/mapBuilderAdmin/install/configure.php b/mapBuilderAdmin/install/configure.php index 488cbe51..17f743f6 100644 --- a/mapBuilderAdmin/install/configure.php +++ b/mapBuilderAdmin/install/configure.php @@ -1,40 +1,37 @@ havingName( 'admin', - array( - new MapInclude('urls.xml') - ) - ) - ; - } - - public function configure(ConfigurationHelpers $helpers) - { - + [ + new MapInclude('urls.xml'), + ] + ); } + public function configure(ConfigurationHelpers $helpers) {} } diff --git a/mapBuilderAdmin/install/install.php b/mapBuilderAdmin/install/install.php index c86ca028..96296554 100644 --- a/mapBuilderAdmin/install/install.php +++ b/mapBuilderAdmin/install/install.php @@ -1,20 +1,21 @@ entryPoint->getEpId() == 'admin') { +class mapBuilderAdminModuleInstaller extends jInstallerModule +{ + public function install() + { + if ('admin' == $this->entryPoint->getEpId()) { $localConfigIni = $this->entryPoint->localConfigIni->getMaster(); $adminControllers = $localConfigIni->getValue('admin', 'simple_urlengine_entrypoints'); $mbCtrl = 'mapBuilderAdmin~*@classic'; - if (strpos($adminControllers, $mbCtrl) === false) { + if (false === strpos($adminControllers, $mbCtrl)) { // let's register mapBuilderAdmin controllers $adminControllers .= ', '.$mbCtrl; $localConfigIni->setValue('admin', $adminControllers, 'simple_urlengine_entrypoints');