/** * constructor * key : the project name * rep : the repository has a lizmapRepository class */ public function __construct($key, $rep) { if (file_exists($rep->getPath() . $key . '.qgs') && file_exists($rep->getPath() . $key . '.qgs.cfg')) { $this->key = $key; $this->repository = $rep; $key_session = $rep->getKey() . '~' . $key; $qgs_path = $rep->getPath() . $key . '.qgs'; $config = null; $qgs_xml = null; $update_session = false; if (isset($_SESSION['_LIZMAP_']) && isset($_SESSION['_LIZMAP_'][$key_session]) && isset($_SESSION['_LIZMAP_'][$key_session]['cfg']) && isset($_SESSION['_LIZMAP_'][$key_session]['cfgmtime']) && $_SESSION['_LIZMAP_'][$key_session]['cfgmtime'] >= filemtime($qgs_path . '.cfg')) { $config = $_SESSION['_LIZMAP_'][$key_session]['cfg']; } else { $config = jFile::read($qgs_path . '.cfg'); $update_session = true; } $this->cfg = json_decode($config); $configOptions = $this->cfg->options; if (isset($_SESSION['_LIZMAP_']) && isset($_SESSION['_LIZMAP_'][$key_session]) && isset($_SESSION['_LIZMAP_'][$key_session]['xml']) && isset($_SESSION['_LIZMAP_'][$key_session]['xmlmtime']) && $_SESSION['_LIZMAP_'][$key_session]['xmlmtime'] >= filemtime($qgs_path)) { $qgs_xml = simplexml_load_string($_SESSION['_LIZMAP_'][$key_session]['xml']); } else { $qgs_xml = simplexml_load_file($qgs_path); $update_session = true; } $this->xml = $qgs_xml; $this->data = array('repository' => $rep->getKey(), 'id' => $key, 'title' => ucfirst($key), 'abstract' => '', 'proj' => $configOptions->projection->ref, 'bbox' => join($configOptions->bbox, ', ')); # get title from WMS properties if (property_exists($qgs_xml->properties, 'WMSServiceTitle')) { if (!empty($qgs_xml->properties->WMSServiceTitle)) { $this->data['title'] = $qgs_xml->properties->WMSServiceTitle; } } # get abstract from WMS properties if (property_exists($qgs_xml->properties, 'WMSServiceAbstract')) { $this->data['abstract'] = $qgs_xml->properties->WMSServiceAbstract; } if ($update_session) { if (!isset($_SESSION['_LIZMAP_'])) { $_SESSION['_LIZMAP_'] = array($key_session => array()); } else { if (!isset($_SESSION['_LIZMAP_'][$key_session])) { $_SESSION['_LIZMAP_'][$key_session] = array(); } } $_SESSION['_LIZMAP_'][$key_session]['xml'] = $qgs_xml->saveXml(); $_SESSION['_LIZMAP_'][$key_session]['xmlmtime'] = filemtime($qgs_path); $_SESSION['_LIZMAP_'][$key_session]['cfg'] = $config; $_SESSION['_LIZMAP_'][$key_session]['cfgmtime'] = filemtime($qgs_path . '.cfg'); } # get WMS getCapabilities full URL $this->data['wmsGetCapabilitiesUrl'] = jUrl::getFull('lizmap~service:index', array('repository' => $rep->getKey(), 'project' => $key, 'SERVICE' => 'WMS', 'VERSION' => '1.3.0', 'REQUEST' => 'GetCapabilities')); // get QGIS project version $qgisRoot = $this->xml->xpath('//qgis'); $qgisRootZero = $qgisRoot[0]; $qgisProjectVersion = (string) $qgisRootZero->attributes()->version; $qgisProjectVersion = explode('-', $qgisProjectVersion); $qgisProjectVersion = $qgisProjectVersion[0]; $qgisProjectVersion = explode('.', $qgisProjectVersion); $a = ''; foreach ($qgisProjectVersion as $k) { if (strlen($k) == 1) { $a .= $k . '0'; } else { $a .= $k; } } $qgisProjectVersion = (int) $a; $this->qgisProjectVersion = $qgisProjectVersion; } }
/** * 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; }
<?php // check version from 2 files : // from the defaultconfig.ini.php file // and // from the VERSION file and compare them $currentVersion = jIniFile::read(jApp::configPath() . 'defaultconfig.ini.php'); $newVersion = jFile::read(jApp::appPath() . 'VERSION'); if (trim($currentVersion['havefnubb']['version']) == trim($newVersion)) { $alreadyInstalled = true; } else { $alreadyInstalled = false; } // check if the application is already installed $appInstalled = file_exists(jApp::configPath() . 'installer.ini.php');
/** * 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; } }
protected function extensionsFiles() { $config = array(); $dir = "modules/"; $tpl = new jTpl(); // $iter = new DirectoryIterator($dir); foreach ($iter as $file) { if (!$file->isDot()) { if ($file->isDir() && file_exists($dir . $file->getFilename() . '/urls.json')) { //get the module xml file $doc = jFile::read($dir . $file->getFilename() . '/urls.json'); $urls = json_decode($doc); foreach ($urls->jsfiles->head as $row) { $config['head'][] = jUrl::get('jelix~www:getfile', array('targetmodule' => $file->getFilename(), 'file' => $row)); } foreach ($urls->jsfiles->bottom as $row) { $config['bottom'][] = jUrl::get('jelix~www:getfile', array('targetmodule' => $file->getFilename(), 'file' => $row)); } } } } return $config; }
/** * Read the qgis files */ protected function readXml($key, $rep) { $qgs_path = $rep->getPath() . $key . '.qgs'; if (!file_exists($qgs_path) || !file_exists($qgs_path . '.cfg')) { throw new Exception("Files of project {$key} does not exists"); } $config = jFile::read($qgs_path . '.cfg'); $this->cfg = json_decode($config); if ($this->cfg === null) { throw new Exception(".qgs.cfg File of project {$key} has invalid content"); } $configOptions = $this->cfg->options; $qgs_xml = simplexml_load_file($qgs_path); if ($qgs_xml === false) { throw new Exception("Qgs File of project {$key} has invalid content"); } $this->xml = $qgs_xml; $this->data = array('repository' => $rep->getKey(), 'id' => $key, 'title' => ucfirst($key), 'abstract' => '', 'proj' => $configOptions->projection->ref, 'bbox' => join($configOptions->bbox, ', ')); # get title from WMS properties if (property_exists($qgs_xml->properties, 'WMSServiceTitle')) { if (!empty($qgs_xml->properties->WMSServiceTitle)) { $this->data['title'] = (string) $qgs_xml->properties->WMSServiceTitle; } } # get abstract from WMS properties if (property_exists($qgs_xml->properties, 'WMSServiceAbstract')) { $this->data['abstract'] = (string) $qgs_xml->properties->WMSServiceAbstract; } # get WMS getCapabilities full URL $this->data['wmsGetCapabilitiesUrl'] = jUrl::getFull('lizmap~service:index', array('repository' => $rep->getKey(), 'project' => $key, 'SERVICE' => 'WMS', 'VERSION' => '1.3.0', 'REQUEST' => 'GetCapabilities')); # get WMTS getCapabilities full URL $this->data['wmtsGetCapabilitiesUrl'] = jUrl::getFull('lizmap~service:index', array('repository' => $rep->getKey(), 'project' => $key, 'SERVICE' => 'WMTS', 'VERSION' => '1.0.0', 'REQUEST' => 'GetCapabilities')); // get QGIS project version $qgisRoot = $qgs_xml->xpath('//qgis'); $qgisRootZero = $qgisRoot[0]; $qgisProjectVersion = (string) $qgisRootZero->attributes()->version; $qgisProjectVersion = explode('-', $qgisProjectVersion); $qgisProjectVersion = $qgisProjectVersion[0]; $qgisProjectVersion = explode('.', $qgisProjectVersion); $a = ''; foreach ($qgisProjectVersion as $k) { if (strlen($k) == 1) { $a .= $k . '0'; } else { $a .= $k; } } $qgisProjectVersion = (int) $a; $this->qgisProjectVersion = $qgisProjectVersion; $shortNames = $qgs_xml->xpath('//maplayer/shortname'); if ($shortNames && count($shortNames) > 0) { foreach ($shortNames as $sname) { $sname = (string) $sname; $xmlLayer = $qgs_xml->xpath("//maplayer[shortname='{$sname}']"); $xmlLayer = $xmlLayer[0]; $name = (string) $xmlLayer->layername; if (property_exists($this->cfg->layers, $name)) { $this->cfg->layers->{$name}->shortname = $sname; } } } $groupsWithShortName = $qgs_xml->xpath("//layer-tree-group/customproperties/property[@key='wmsShortName']/parent::*/parent::*"); if ($groupsWithShortName && count($groupsWithShortName) > 0) { foreach ($groupsWithShortName as $group) { $name = (string) $group['name']; $shortNameProperty = $group->xpath("customproperties/property[@key='wmsShortName']"); if ($shortNameProperty && count($shortNameProperty) > 0) { $shortNameProperty = $shortNameProperty[0]; $sname = (string) $shortNameProperty['value']; if (property_exists($this->cfg->layers, $name)) { $this->cfg->layers->{$name}->shortname = $sname; } } } } $layersWithShowFeatureCount = $qgs_xml->xpath("//layer-tree-layer/customproperties/property[@key='showFeatureCount']/parent::*/parent::*"); if ($layersWithShowFeatureCount && count($layersWithShowFeatureCount) > 0) { foreach ($layersWithShowFeatureCount as $layer) { $name = (string) $layer['name']; if (property_exists($this->cfg->layers, $name)) { $this->cfg->layers->{$name}->showFeatureCount = 'True'; } } } //remove plugin layer $pluginLayers = $qgs_xml->xpath('//maplayer[type="plugin"]'); if ($pluginLayers && count($pluginLayers) > 0) { foreach ($pluginLayers as $layer) { $name = (string) $layer->layername; if (property_exists($this->cfg->layers, $name)) { unset($this->cfg->layers->{$name}); } } } //unset cache for editionLayers if (property_exists($this->cfg, 'editionLayers')) { foreach ($this->cfg->editionLayers as $key => $obj) { if (property_exists($this->cfg->layers, $key)) { $this->cfg->layers->{$key}->cached = 'False'; $this->cfg->layers->{$key}->clientCacheExpiration = 0; if (property_exists($this->cfg->layers->{$key}, 'cacheExpiration')) { unset($this->cfg->layers->{$key}->cacheExpiration); } } } } //unset cache for loginFilteredLayers if (property_exists($this->cfg, 'loginFilteredLayers')) { foreach ($this->cfg->loginFilteredLayers as $key => $obj) { if (property_exists($this->cfg->layers, $key)) { $this->cfg->layers->{$key}->cached = 'False'; $this->cfg->layers->{$key}->clientCacheExpiration = 0; if (property_exists($this->cfg->layers->{$key}, 'cacheExpiration')) { unset($this->cfg->layers->{$key}->cacheExpiration); } } } } //unset displayInLegend for geometryType none or unknown foreach ($this->cfg->layers as $key => $obj) { if (property_exists($this->cfg->layers->{$key}, 'geometryType') && ($this->cfg->layers->{$key}->geometryType == 'none' || $this->cfg->layers->{$key}->geometryType == 'unknown')) { $this->cfg->layers->{$key}->displayInLegend = 'False'; } } $this->WMSInformation = $this->readWMSInformation($qgs_xml); $this->canvasColor = $this->readCanvasColor($qgs_xml); $this->allProj4 = $this->readAllProj4($qgs_xml); $this->relations = $this->readRelations($qgs_xml); $this->layersOrder = $this->readLayersOrder($qgs_xml); $this->printCapabilities = $this->readPrintCapabilities($qgs_xml, $this->cfg); $this->locateByLayer = $this->readLocateByLayers($qgs_xml, $this->cfg); $this->editionLayers = $this->readEditionLayers($qgs_xml, $this->cfg); $this->useLayerIDs = $this->readUseLayerIDs($qgs_xml); $this->layers = $this->readLayers($qgs_xml); }