<commit_before><?php
/**
 * Displays a full featured map based on one Qgis project.
 *
 * @author    3liz
 * @copyright 2011 3liz
 *
 * @see      http://3liz.com
 *
 * @license    Mozilla Public License : http://www.mozilla.org/MPL/
 */
class lizMapCtrl extends jController
{
    // repositoryKey: Used to pass repository key
    protected $repositoryKey;
    // projectKey: Used to pass project key
    protected $projectKey;

    /**
     * Used to pass project Object (no need to rebuild it).
     *
     * @var \Lizmap\Project\Project
     */
    protected $projectObj;

    // forceHiddenProjectVisible: Used to override plugin configuration hideProject
    // (helpfull for modules which maps are based on a hidden project)
    protected $forceHiddenProjectVisible = false;

    /**
     * Load the map page for the given project.
     *
     * @param string $repository name of the repository
     * @param string $project    name of the project
     *
     * @return jResponse with map and content for the chose Qgis project
     */
    public function index()
    {
        if ($this->param('theme')) {
            jApp::config()->theme = $this->param('theme');
        }
        $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);
        }

        // default response
        // redirection if error encountered
        $rep = $this->getResponse('redirect');
        $rep->action = 'view~default:index';

        if (!$lrep or !jAcl2::check('lizmap.repositories.view', $lrep->getKey())) {
            jMessage::add(jLocale::get('view~default.repository.access.denied'), 'error');
            if (!jAuth::isConnected()) {
                $rep->action = 'jcommunity~login:index';
            }

            return $rep;
        }

        // We must redirect to default repository project list if no project given
        if (!$project) {
            try {
                $lproj = lizmap::getProject($lrep->getKey().'~'.$lser->defaultProject);
                if (!$lproj) {
                    jMessage::add('The parameter project is mandatory!', 'error');

                    return $rep;
                }
                $project = $lser->defaultProject;
            } catch (UnknownLizmapProjectException $e) {
                jMessage::add('The parameter project is mandatory!', 'error');

                return $rep;
            }
        }

        // Get the project
        try {
            $lproj = lizmap::getProject($lrep->getKey().'~'.$project);
            if (!$lproj) {
                jMessage::add('The lizmap project '.strtoupper($project).' does not exist !', 'error');

                return $rep;
            }
        } catch (UnknownLizmapProjectException $e) {
            jMessage::add('The lizmap project '.strtoupper($project).' does not exist !', 'error');

            return $rep;
        }

        // Redirect if no right to access the project
        if (!$lproj->checkAcl()) {
            jMessage::add(jLocale::get('view~default.repository.access.denied'), 'error');
            if (!jAuth::isConnected()) {
                $rep->action = 'jcommunity~login:index';
            }

            return $rep;
        }

        // Redirect if project is hidden (lizmap plugin option)
        if (!$this->forceHiddenProjectVisible) {
            if ($lproj->getBooleanOption('hideProject')) {
                jMessage::add(jLocale::get('view~default.project.access.denied'), 'error');

                return $rep;
            }
        }

        // the html response
        $rep = $this->getResponse('htmlmap');
        $rep->addJSLink((jUrl::get('view~translate:index')).'?lang='.jApp::config()->locale);

        $this->repositoryKey = $lrep->getKey();
        $this->projectKey = $lproj->getKey();
        $this->projectObj = $lproj;

        // 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&key='.$googleKey);
            } else {
                $rep->addJSLink('https://maps.google.com/maps/api/js?v=3');
            }
        }

        $confUrlEngine = &jApp::config()->urlengine;
        $bp = $confUrlEngine['basePath'];

        // Add the jForms js
        if ($lproj->hasEditionLayersForCurrentUser()) {
            $lang = jLocale::getCurrentLang();
            $www = $confUrlEngine['jelixWWWPath'];

            $rep->addJSLink($www.'jquery/include/jquery.include.js');
            $rep->addJSLink($www.'js/jforms_jquery.js');

            // for imageupload
            $rep->addJSLink($www.'js/cropper.min.js');
            $rep->addJSLink($www.'js/jforms/choice.js');
            $rep->addJSLink($www.'js/jforms/imageSelector.js');
            $rep->addCSSLink($www.'js/cropper.min.css');

            // Add datepickers jForms js
            $confDate = &jApp::config()->datepickers;
            $rep->addJSLink($confDate['default']);
            if (isset($confDate['default.js'])) {
                $js = $confDate['default.js'];
                foreach ($js as $file) {
                    $file = str_replace('$lang', $lang, $file);
                    if (strpos($file, 'jquery.ui.datepicker-en.js') !== false) {
                        continue;
                    }
                    $rep->addJSLink($file);
                }
            }

            // Add other jForms js
            $rep->addJSLink($bp.'assets/js/ckeditor5/ckeditor.js');
            $rep->addJSLink($bp.'assets/js/ckeditor5/ckeditor_lizmap.js');
            $rep->addJSLink($bp.'assets/js/fileUpload/jquery.fileupload.js');
            $rep->addJSLink($bp.'assets/js/bootstrapErrorDecoratorHtml.js');
        }

        // Add bottom dock js
        $rep->addJSLink($bp.'assets/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'),
            'keyValueConfig' => jUrl::getFull('lizmap~service:getKeyValueConfig'),
            '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.'assets/js/dataTables/'.jApp::config()->locale.'.json',
            'basepath' => $bp,
            'geobookmark' => jUrl::get('lizmap~geobookmark:index'),
        );

        // Get optional WMS public url list
        $lser = lizmap::getServices();
        if ($lser->wmsPublicUrlList) {<commit_msg>Fix: getFull => get for getKeyValueConfig<commit_after><?php
/**
 * Displays a full featured map based on one Qgis project.
 *
 * @author    3liz
 * @copyright 2011 3liz
 *
 * @see      http://3liz.com
 *
 * @license    Mozilla Public License : http://www.mozilla.org/MPL/
 */
class lizMapCtrl extends jController
{
    // repositoryKey: Used to pass repository key
    protected $repositoryKey;
    // projectKey: Used to pass project key
    protected $projectKey;

    /**
     * Used to pass project Object (no need to rebuild it).
     *
     * @var \Lizmap\Project\Project
     */
    protected $projectObj;

    // forceHiddenProjectVisible: Used to override plugin configuration hideProject
    // (helpfull for modules which maps are based on a hidden project)
    protected $forceHiddenProjectVisible = false;

    /**
     * Load the map page for the given project.
     *
     * @param string $repository name of the repository
     * @param string $project    name of the project
     *
     * @return jResponse with map and content for the chose Qgis project
     */
    public function index()
    {
        if ($this->param('theme')) {
            jApp::config()->theme = $this->param('theme');
        }
        $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);
        }

        // default response
        // redirection if error encountered
        $rep = $this->getResponse('redirect');
        $rep->action = 'view~default:index';

        if (!$lrep or !jAcl2::check('lizmap.repositories.view', $lrep->getKey())) {
            jMessage::add(jLocale::get('view~default.repository.access.denied'), 'error');
            if (!jAuth::isConnected()) {
                $rep->action = 'jcommunity~login:index';
            }

            return $rep;
        }

        // We must redirect to default repository project list if no project given
        if (!$project) {
            try {
                $lproj = lizmap::getProject($lrep->getKey().'~'.$lser->defaultProject);
                if (!$lproj) {
                    jMessage::add('The parameter project is mandatory!', 'error');

                    return $rep;
                }
                $project = $lser->defaultProject;
            } catch (UnknownLizmapProjectException $e) {
                jMessage::add('The parameter project is mandatory!', 'error');

                return $rep;
            }
        }

        // Get the project
        try {
            $lproj = lizmap::getProject($lrep->getKey().'~'.$project);
            if (!$lproj) {
                jMessage::add('The lizmap project '.strtoupper($project).' does not exist !', 'error');

                return $rep;
            }
        } catch (UnknownLizmapProjectException $e) {
            jMessage::add('The lizmap project '.strtoupper($project).' does not exist !', 'error');

            return $rep;
        }

        // Redirect if no right to access the project
        if (!$lproj->checkAcl()) {
            jMessage::add(jLocale::get('view~default.repository.access.denied'), 'error');
            if (!jAuth::isConnected()) {
                $rep->action = 'jcommunity~login:index';
            }

            return $rep;
        }

        // Redirect if project is hidden (lizmap plugin option)
        if (!$this->forceHiddenProjectVisible) {
            if ($lproj->getBooleanOption('hideProject')) {
                jMessage::add(jLocale::get('view~default.project.access.denied'), 'error');

                return $rep;
            }
        }

        // the html response
        $rep = $this->getResponse('htmlmap');
        $rep->addJSLink((jUrl::get('view~translate:index')).'?lang='.jApp::config()->locale);

        $this->repositoryKey = $lrep->getKey();
        $this->projectKey = $lproj->getKey();
        $this->projectObj = $lproj;

        // 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&key='.$googleKey);
            } else {
                $rep->addJSLink('https://maps.google.com/maps/api/js?v=3');
            }
        }

        $confUrlEngine = &jApp::config()->urlengine;
        $bp = $confUrlEngine['basePath'];

        // Add the jForms js
        if ($lproj->hasEditionLayersForCurrentUser()) {
            $lang = jLocale::getCurrentLang();
            $www = $confUrlEngine['jelixWWWPath'];

            $rep->addJSLink($www.'jquery/include/jquery.include.js');
            $rep->addJSLink($www.'js/jforms_jquery.js');

            // for imageupload
            $rep->addJSLink($www.'js/cropper.min.js');
            $rep->addJSLink($www.'js/jforms/choice.js');
            $rep->addJSLink($www.'js/jforms/imageSelector.js');
            $rep->addCSSLink($www.'js/cropper.min.css');

            // Add datepickers jForms js
            $confDate = &jApp::config()->datepickers;
            $rep->addJSLink($confDate['default']);
            if (isset($confDate['default.js'])) {
                $js = $confDate['default.js'];
                foreach ($js as $file) {
                    $file = str_replace('$lang', $lang, $file);
                    if (strpos($file, 'jquery.ui.datepicker-en.js') !== false) {
                        continue;
                    }
                    $rep->addJSLink($file);
                }
            }

            // Add other jForms js
            $rep->addJSLink($bp.'assets/js/ckeditor5/ckeditor.js');
            $rep->addJSLink($bp.'assets/js/ckeditor5/ckeditor_lizmap.js');
            $rep->addJSLink($bp.'assets/js/fileUpload/jquery.fileupload.js');
            $rep->addJSLink($bp.'assets/js/bootstrapErrorDecoratorHtml.js');
        }

        // Add bottom dock js
        $rep->addJSLink($bp.'assets/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'),
            'keyValueConfig' => jUrl::get('lizmap~service:getKeyValueConfig'),
            '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.'assets/js/dataTables/'.jApp::config()->locale.'.json',
            'basepath' => $bp,
            'geobookmark' => jUrl::get('lizmap~geobookmark:index'),
        );

        // Get optional WMS public url list
        $lser = lizmap::getServices();
        if ($lser->wmsPublicUrlList) {
{'fraction_non_alphanumeric': 0.1518363489062922, 'fraction_numerical': 0.0016203078584931137, 'mean_word_length': 1.986491935483871, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 130, 'https://': 4, 'lorem ipsum': 0, 'www.': 16, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4886220', 'n_tokens_mistral': 4344, 'n_tokens_neox': 4233, 'n_words': 844}