[Cartoweb-users] Problem ini file parsing and question about switches

Alexandre Saunier alexandre.saunier at camptocamp.com
Fri Apr 13 05:44:19 EDT 2007


Hello

Dirk Jesko wrote:
> 1. I have extended the exportPdf plugin to handle copyright strings. The 
> plan is to define the strings in exportPdf.ini in the following way
> 
> copyright.0.layers = layer1, layer2, ...
> copyright.0.text = "Copyright message 1"
> copyright.1.layers = layer3, layer4, ...
> copyright.1.text = "Copyright message 2"
> ...
> 
> Then I would like to retrieve the information in the client part of the 
> plugin. However, as soon as the definition are added to exportPdf.ini, I 
> get the following error while Cartoweb is loading
> 
> PHP Parse error:  parse error, unexpected T_LNUMBER, expecting T_STRING 
> or T_VARIABLE or '{' or '$' in 
> C:\www\cartoweb3\common\StructHandler.php(47) : eval()'d code on line 1
> 
> If I remove the numbers from the keys, e.g. copyright.layers instead of  
> copyright.0.layers The error disappears. Since the same kind of 
> definition work in locate.ini, I am a little confused.

I'm pretty confused as well since your exportPdf.ini syntax is not 
standard at all! Have you extended the ClientExportPdf class in some way 
of your own to make it read such a configuration?

The standard syntax for blocks in exportPdf.ini is something like:
blocks.copyright.content = "Copyright message"

In the standard exportPdf plugin I don't think there's a way to switch 
the copyright text depending on the layers selection. However that 
should be possible by doing something like (not tested):

1. extend the exportPdf plugin client class (ClientExportPdf) in your 
project

2. overload the ClientExportPdf::createBlock() method and replace the 
following code:

  490         if ($this->blocks[$id]->type == 'text' &&
  491             (stristr($this->blocks[$id]->content, 'file~') ||
  492              stristr($this->blocks[$id]->content, 'db~'))) {
  493             $this->blocks[$id]->content =
  494                 PrintTools::getContent($this->blocks[$id]->content);
  495         }

by

  490         if ($this->blocks[$id]->type == 'text' &&
  491             (stristr($this->blocks[$id]->content, 'file~') ||
  492              stristr($this->blocks[$id]->content, 'layers~') ||
  493              stristr($this->blocks[$id]->content, 'db~'))) {
  494             $this->blocks[$id]->content =
  495                 PrintTools::getContent($this->blocks[$id]->content);
  496         }

(I've added a test at line 492, the "layers" keyword is probably not the 
best choice, maybe you'd better picker a more adapted one)

3. extends the PrintTools class (located in 
exportPdf/client/ExportPdfObjects.php, you might have to edit the new 
file inclusion in your plugin extension at step 1)

4. overload the PrintTools::getContent() method by replacing the 
following code:
83     static public function getContent($storage) {
  84         $storageInfo = explode('~', $storage);
  85         switch($storageInfo[0]) {
  86             case 'file': return self::getFileContent($storageInfo);
  87             case 'db': return self::getDbContent($storageInfo);
  88             default: return $storage;
  89         }
  90     }

by

83     static public function getContent($storage) {
  84         $storageInfo = explode('~', $storage);
  85         switch($storageInfo[0]) {
  86             case 'file': return self::getFileContent($storageInfo);
  87             case 'db': return self::getDbContent($storageInfo);
  88             case 'layers': return self::getLayersContent($storageInfo);
  89             default: return $storage;
  90         }
  91     }

(I've added a case at line 88)

5. Adds the following static method to PrintTools:

static protected function getLayersContent($info) {
     // access to layers selection
     // using 
$cartoclient->getPluginManager()->getPlugin('layers')->getLayerIds()
     // might be tricking since PrintTools has no direct access to the 
$cartoclient object...

     // depending on the layers selection, pick the correct copyright text

     return $content;
}

6. In exportPdf.ini set:
blocks.exportPdf.content = layers~

I hope this will help.
AS


More information about the Cartoweb-users mailing list