From 0371547fc5d3fa6435887b2d8e45b14126d7eec3 Mon Sep 17 00:00:00 2001 From: Drillin Pierre Date: Thu, 21 Jan 2021 16:28:25 +0100 Subject: [PATCH 1/2] Adding php-cs-fixer --- .github/workflows/test-lint-php.yml | 22 ++++++++++++ .php_cs.dist | 52 +++++++++++++++++++++++++++++ Makefile | 5 +++ 3 files changed, 79 insertions(+) create mode 100644 .github/workflows/test-lint-php.yml create mode 100644 .php_cs.dist create mode 100644 Makefile diff --git a/.github/workflows/test-lint-php.yml b/.github/workflows/test-lint-php.yml new file mode 100644 index 00000000..7190f018 --- /dev/null +++ b/.github/workflows/test-lint-php.yml @@ -0,0 +1,22 @@ + +name: Tests 🎳 + +on: + push: +# paths: +# - '**.php' + pull_request: +# paths: +# - '**.php' + +jobs: + test-php-cs-fixer: + name: "PHP-CS-Fixer" + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@master + + - uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --config=.php_cs.dist --allow-risky=yes --dry-run --diff -- mapBuilder diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 00000000..21a0b41d --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,52 @@ +in(array( + __DIR__.'/mapBuilder', + )) + ; + +return PhpCsFixer\Config::create() + ->setCacheFile(__DIR__.'/.php_cs.cache') + ->setRules([ + '@PSR2' => true, + '@Symfony' => true, + '@PhpCsFixer' => true, + 'array_syntax' => array('syntax'=>'long'), + 'method_argument_space'=> ['on_multiline' => 'ensure_fully_multiline'], + 'new_with_braces'=> true, + 'no_whitespace_in_blank_line'=> true, + 'no_whitespace_before_comma_in_array'=> true, + 'no_useless_return' => true, + 'no_unneeded_final_method'=> true, + 'no_unset_cast' => false, + 'no_leading_import_slash'=> true, + 'no_leading_namespace_whitespace'=> true, + 'no_extra_blank_lines'=> true, + 'no_empty_statement'=> true, + 'no_empty_comment'=> true, + 'object_operator_without_whitespace' => true, + 'ordered_class_elements' => false, + 'phpdoc_var_without_name' => true, + 'phpdoc_types' => true, + 'phpdoc_trim_consecutive_blank_line_separation' => true, + 'phpdoc_no_useless_inheritdoc' => true, + 'phpdoc_no_empty_return' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'protected_to_private' => false, + 'semicolon_after_instruction' => true, + 'short_scalar_cast' => true, + 'simplified_null_return' => false, + 'simple_to_complex_string_variable' => false, + 'standardize_not_equals' => true, + 'standardize_increment' => true, + 'whitespace_after_comma_in_array' => true, + 'yoda_style'=>array( + 'always_move_variable' => false, + 'equal' => false, + 'identical' => false, + 'less_and_greater' => null, + ) + ]) + ->setFinder($finder) + ; diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..4eb4ca76 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +php-cs-fixer-test: + php-cs-fixer fix --config=.php_cs.dist --allow-risky=yes --dry-run --diff + +php-cs-fixer-apply: + php-cs-fixer fix --config=.php_cs.dist --allow-risky=yes \ No newline at end of file From 7fcc7a0a1ca08968fb3fcf0b82df34674d3c6506 Mon Sep 17 00:00:00 2001 From: Drillin Pierre Date: Thu, 21 Jan 2021 16:34:25 +0100 Subject: [PATCH 2/2] Apply php-c-fixer --- .gitignore | 2 + Makefile | 2 +- mapBuilder/classes/listBaseLayer.class.php | 77 +++++----- mapBuilder/classes/listRepositories.class.php | 53 ++++--- .../classes/mapBuilderView.listener.php | 41 +++--- mapBuilder/controllers/default.classic.php | 135 +++++++++--------- mapBuilder/controllers/mapcontext.classic.php | 118 ++++++++------- mapBuilder/install/conf/mapBuilder.ini.php | 2 +- mapBuilder/install/install.php | 30 ++-- mapBuilder/install/upgrade.php | 22 +-- mapBuilder/install/upgrade_acl.php | 32 ++--- mapBuilder/install/upgrade_createtable.php | 26 ++-- .../install/upgrade_toggleattributetable.php | 26 ++-- mapBuilder/zones/list_mapcontext.zone.php | 97 ++++++------- 14 files changed, 330 insertions(+), 333 deletions(-) diff --git a/.gitignore b/.gitignore index 1fe1b00e..4cb6b037 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea/ node_modules/ + +.php_cs.caches diff --git a/Makefile b/Makefile index 4eb4ca76..84854777 100644 --- a/Makefile +++ b/Makefile @@ -2,4 +2,4 @@ php-cs-fixer-test: php-cs-fixer fix --config=.php_cs.dist --allow-risky=yes --dry-run --diff php-cs-fixer-apply: - php-cs-fixer fix --config=.php_cs.dist --allow-risky=yes \ No newline at end of file + php-cs-fixer fix --config=.php_cs.dist --allow-risky=yes diff --git a/mapBuilder/classes/listBaseLayer.class.php b/mapBuilder/classes/listBaseLayer.class.php index 56c2f543..1ea78439 100644 --- a/mapBuilder/classes/listBaseLayer.class.php +++ b/mapBuilder/classes/listBaseLayer.class.php @@ -1,44 +1,43 @@ -formId = $id; - - $this->data = array( - 'osmMapnik' => 'OSM Mapnik', - 'osmStamenToner' => 'OSM Stamen Toner', - 'osmCyclemap' => 'OSM Cyclemap', - 'bingStreets' => 'Bing Streets', - 'bingSatellite' => 'Bing Satellite', - 'bingHybrid' => 'Bing Hybrid', - 'ignTerrain' => 'IGN Terrain', - '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 = array(); + + public function __construct($id) + { + $this->formId = $id; + + $this->data = array( + 'osmMapnik' => 'OSM Mapnik', + 'osmStamenToner' => 'OSM Stamen Toner', + 'osmCyclemap' => 'OSM Cyclemap', + 'bingStreets' => 'Bing Streets', + 'bingSatellite' => 'Bing Satellite', + 'bingHybrid' => 'Bing Hybrid', + 'ignTerrain' => 'IGN Terrain', + '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 d8cd7c43..b0fdaf6e 100644 --- a/mapBuilder/classes/listRepositories.class.php +++ b/mapBuilder/classes/listRepositories.class.php @@ -1,41 +1,40 @@ -formId = $id; + public function __construct($id) + { + $this->formId = $id; - $repositories = array(); + $repositories = array(); - 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 e20c5c54..0782903e 100644 --- a/mapBuilder/classes/mapBuilderView.listener.php +++ b/mapBuilder/classes/mapBuilderView.listener.php @@ -1,10 +1,12 @@ transform($sourceProj,$destProj,$sourceMinPt); - $destMaxPt = $proj4->transform($sourceProj,$destProj,$sourceMaxPt); - - $extent = implode(", ", array( $destMinPt->x, $destMinPt->y, $destMaxPt->x, $destMaxPt->y )); + $destMinPt = $proj4->transform($sourceProj, $destProj, $sourceMinPt); + $destMaxPt = $proj4->transform($sourceProj, $destProj, $sourceMaxPt); + $extent = implode(', ', array($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'); @@ -64,7 +65,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 633871d5..1ba3214a 100644 --- a/mapBuilder/controllers/default.classic.php +++ b/mapBuilder/controllers/default.classic.php @@ -1,32 +1,31 @@ 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 // Get lizmap services $services = lizmap::getServices(); - $title = jLocale::get('mapBuilder~default.app.name');; + $title = jLocale::get('mapBuilder~default.app.name'); $rep->title = $title; $rep->metaViewport = 'initial-scale=1.0, user-scalable=no, width=device-width, shrink-to-fit=no'; @@ -46,22 +45,22 @@ function index() { // 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') + '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(jApp::configPath('mapBuilder.ini.php'), True); + $readConfigPath = parse_ini_file(jApp::configPath('mapBuilder.ini.php'), true); // Build repository + project tree for FancyTree $nestedTree = array(); @@ -69,33 +68,33 @@ function index() { $repositoryList = array(); // 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(); foreach ($projects as $project) { - $projectArray[] = [ - "title" => $project->getData('title'), - "folder" => true, - "lazy" => true, - "repository" => $repositoryName, - "project" => $project->getKey() - ]; + $projectArray[] = array( + 'title' => $project->getData('title'), + 'folder' => true, + 'lazy' => true, + 'repository' => $repositoryName, + 'project' => $project->getKey(), + ); } - $nestedTree[] = [ - "title" => $repository->getData('label'), - "folder" => true, - "children" => $projectArray - ]; + $nestedTree[] = array( + 'title' => $repository->getData('label'), + 'folder' => true, + 'children' => $projectArray, + ); } } @@ -103,11 +102,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'); @@ -116,7 +115,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]); } } @@ -124,43 +123,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(); $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 $lineContent != '\n') { + $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).';'); @@ -170,7 +171,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 != '' && preg_match('/^UA-\\d+-\\d+$/', $services->googleAnalyticsID) == 1) { $rep->body->assign('googleAnalyticsID', $services->googleAnalyticsID); } @@ -180,9 +181,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..f3e3143b 100644 --- a/mapBuilder/controllers/mapcontext.classic.php +++ b/mapBuilder/controllers/mapcontext.classic.php @@ -1,32 +1,29 @@ getResponse('htmlfragment'); // Make sure that it is a POST request. - if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){ + if (strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0) { 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 +33,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 (strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0) { throw new Exception('Request method must be POST!'); } @@ -79,19 +75,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 ($mcCount != 1) { 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,11 +96,9 @@ function delete(){ return $rep; } - /* - * Get mapcontext by id - * - */ - function get(){ + // Get mapcontext by id + public function get() + { // Get user $juser = jAuth::getUserSession(); @@ -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 ($mcCount != 1) { + 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 = array(); + 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 8e822c0c..befd063d 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/install.php b/mapBuilder/install/install.php index cf071192..5fa147d3 100644 --- a/mapBuilder/install/install.php +++ b/mapBuilder/install/install.php @@ -1,16 +1,16 @@ copyDirectoryContent('../www/css', jApp::wwwPath('mapBuilder/css')); $this->copyDirectoryContent('../www/js/dist', jApp::wwwPath('mapBuilder/js')); @@ -26,15 +26,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 b334ea28..a11a0793 100644 --- a/mapBuilder/install/upgrade.php +++ b/mapBuilder/install/upgrade.php @@ -1,16 +1,16 @@ copyDirectoryContent('../www/css', jApp::wwwPath('mapBuilder/css'), true); $this->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..17343e37 100644 --- a/mapBuilder/install/upgrade_acl.php +++ b/mapBuilder/install/upgrade_acl.php @@ -1,30 +1,30 @@ 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..fec57331 100644 --- a/mapBuilder/install/upgrade_createtable.php +++ b/mapBuilder/install/upgrade_createtable.php @@ -1,23 +1,23 @@ 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 a6547e88..6cf896bb 100644 --- a/mapBuilder/install/upgrade_toggleattributetable.php +++ b/mapBuilder/install/upgrade_toggleattributetable.php @@ -1,23 +1,23 @@ setValue('attributeTableTool', 'true'); $ini->save(); } diff --git a/mapBuilder/zones/list_mapcontext.zone.php b/mapBuilder/zones/list_mapcontext.zone.php index c6d529b8..7199b56a 100644 --- a/mapBuilder/zones/list_mapcontext.zone.php +++ b/mapBuilder/zones/list_mapcontext.zone.php @@ -1,52 +1,53 @@ 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); + } }