X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-plugins%2Ffai%2Fadmin%2Ffai%2Fclass_debconfTemplate.inc;h=40bd0137299e39145a064efbfd56623ec52a7181;hb=ff3ef83f8dcb54659807a39f8513486b5c0badb0;hp=d781321ec8daba9f701e18fa561ff5738a966e41;hpb=9169b2843e25912293f2c2ef8f96278b52b9fbae;p=gosa.git diff --git a/gosa-plugins/fai/admin/fai/class_debconfTemplate.inc b/gosa-plugins/fai/admin/fai/class_debconfTemplate.inc index d781321ec..40bd01372 100644 --- a/gosa-plugins/fai/admin/fai/class_debconfTemplate.inc +++ b/gosa-plugins/fai/admin/fai/class_debconfTemplate.inc @@ -5,174 +5,123 @@ class debconf var $package= ""; var $language= ""; var $loaded_template= FALSE; - var $template_directory= ""; var $template= array(); - function debconf($package= "", $language= "") + function debconf($language= "") { $this->set_language($language); - $this->set_package($package); } - - function set_package($package) - { - $this->package= $package; - } - - - function set_template_directory($directory) - { - if (is_dir($directory) && is_readable($directory)){ - $this->template_directory = $directory; - return TRUE; - } - - $this->template_directory= ""; - return FALSE; - } - - function set_language($language) { $this->language= $language; } - - function load() + function load_from_string($str) { - if( TRUE === $this->has_template() ) { - - /* Try to load package based template file */ - $this->template= array(); - - /* Read template array */ - $post_name = 0; - $langcode = $this->language.".UTF-8"; - $in_description = FALSE; - $got_local_description = FALSE; - - /* get filename */ - $filename= preg_replace("/\/+/", "/", $this->template_directory."/".$this->package.".templates"); - - /* Check if file is readable */ - if (!is_file($filename) || !is_readable($filename)){ - return(FALSE); + $lines = explode("\n",$str); + $this->template = array(); + $post_name = 0; + $langcode = $this->language.".UTF-8"; + $in_description = FALSE; + $got_local_description = FALSE; + + foreach($lines as $line){ + + /* Reset description flag */ + if ($in_description && !preg_match("/^ /", $line)){ + $in_description= FALSE; } - /* Open file and read content line by line */ - $fh= fopen($filename, 'r'); - - /* While the file handle is valid && there is still data to read -> parse configuration file */ - while ($fh && !feof($fh)){ - $line= fgets($fh, 1024); - - /* Reset description flag */ - if ($in_description && !preg_match("/^ /", $line)){ - $in_description= FALSE; - } + /* Template header */ + if (preg_match("/^Template: /", $line)){ + $post_name ++; + $name= trim(preg_replace("/^Template: (.*)$/", "\\1", $line)); + $this->template[$post_name]['Name'] = $name; + $this->template[$post_name]['Default'] =""; - /* Template header */ - if (preg_match("/^Template: /", $line)){ - $post_name ++; - $name= trim(preg_replace("/^Template: (.*)$/", "\\1", $line)); - $this->template[$post_name]['Name'] = $name; - $this->template[$post_name]['Default'] =""; - - $got_local_description= FALSE; - continue; - } - - /* Get type */ - if (preg_match("/^Type: /", $line)){ - $type= trim(preg_replace("/^Type: (.*)$/", "\\1", $line)); - $this->template[$post_name]['Type']= $type; - continue; - } - - /* Get default */ - if (preg_match("/^Default: /", $line)){ - $this->template[$post_name]['Default']= ""; - $default= trim(preg_replace("/^Default: (.*)$/", "\\1", $line)); - $this->template[$post_name]['Default']= $default; - continue; - } + $got_local_description= FALSE; + continue; + } - /* Get description */ - if (!$got_local_description && preg_match("/^Description: /", $line)){ - $this->template[$post_name]['Description']= ""; - $description= trim(preg_replace("/^Description: (.*)$/", "\\1", $line)); - $this->template[$post_name]['Topic']= $description; - $this->template[$post_name]['Description']= ""; - $in_description= TRUE; - continue; - } + /* Get type */ + if (preg_match("/^Type: /", $line)){ + $type= trim(preg_replace("/^Type: (.*)$/", "\\1", $line)); + $this->template[$post_name]['Type']= $type; + continue; + } - /* Fill description */ - if (!$got_local_description && $in_description){ - $description= preg_replace("/^ (.*)$/", "\\1", $line); - $this->template[$post_name]['Description'].= $description; - continue; - } + /* Get default */ + if (preg_match("/^Default: /", $line)){ + $this->template[$post_name]['Default']= ""; + $default= trim(preg_replace("/^Default: (.*)$/", "\\1", $line)); + $this->template[$post_name]['Default']= $default; + continue; + } - /* Get local description */ - if (preg_match("/^Description-$langcode: /", $line)){ - $description= trim(preg_replace("/^Description-$langcode: (.*)$/", "\\1", $line)); - $this->template[$post_name]['Topic']= $description; - $in_description= TRUE; - $got_local_description= TRUE; - $this->template[$post_name]['Description']= ""; - continue; - } + /* Get description */ + if (!$got_local_description && preg_match("/^Description: /i", $line)){ + $description= trim(preg_replace("/^Description: (.*)$/i", "\\1", $line)); + $this->template[$post_name]['Topic']= $description; + $this->template[$post_name]['Description']= ""; + $in_description= TRUE; + continue; + } - /* Fill local description */ - if ($got_local_description && $in_description){ - $description= preg_replace("/^ (.*)$/", "\\1", $line); - $this->template[$post_name]['Description'].= $description; - continue; - } + /* Fill description */ + if (!$got_local_description && $in_description){ + $description= preg_replace("/^ (.*)$/", "\\1", $line); + $this->template[$post_name]['Description'].= $description; + continue; + } - /* Get native choices */ - if (preg_match("/^Choices: /", $line)){ - $type= trim(preg_replace("/^Choices: (.*)$/", "\\1", $line)); - $this->template[$post_name]['Choices']= $type; - } + /* Get local description */ + if (preg_match("/^Description-$langcode: /i", $line)){ + $description= trim(preg_replace("/^Description-$langcode: (.*)$/i", "\\1", $line)); + $this->template[$post_name]['Topic']= $description; + $in_description= TRUE; + $got_local_description= TRUE; + $this->template[$post_name]['Description']= ""; + continue; + } - /* Get local choices */ - if (preg_match("/^Choices-$langcode: /", $line)){ - $type= trim(preg_replace("/^Choices-$langcode: (.*)$/", "\\1", $line)); - $this->template[$post_name]['Choices-local']= $type; - } + /* Fill local description */ + if ($got_local_description && $in_description){ + $description= preg_replace("/^ (.*)$/", "\\1", $line); + $this->template[$post_name]['Description'].= $description; + continue; + } + /* Get native choices */ + if (preg_match("/^Choices: /", $line)){ + $type= trim(preg_replace("/^Choices: (.*)$/", "\\1", $line)); + $this->template[$post_name]['Choices']= $type; } - fclose($fh); - $this->loaded_template= TRUE; - - $tmp= array(); - foreach($this->template as $post_name => $template){ - $template['post_name'] = "post_".$post_name; - $tmp[] = $template; + /* Get local choices */ + if (preg_match("/^Choices-$langcode: /", $line)){ + $type= trim(preg_replace("/^Choices-$langcode: (.*)$/", "\\1", $line)); + $this->template[$post_name]['Choices-local']= $type; } - $this->template = $tmp; - return (TRUE); } - $this->loaded_template= FALSE; - return (FALSE); - } + $this->loaded_template= TRUE; + $tmp= array(); + foreach($this->template as $post_name => $template){ + $template['post_name'] = "post_".$post_name; + $tmp[] = $template; + } + $this->template = $tmp; + + return (TRUE); + } function has_template() { - /* Reject requests, if parameters are not set */ - if ($this->package == "" || $this->template_directory == ""){ - return (FALSE); - } - $filename= preg_replace("/\/+/", "/", $this->template_directory."/".$this->package.".templates"); - return (is_file($filename) && is_readable($filename)); + return(count($this->template) != FALSE); } @@ -210,8 +159,6 @@ class debconf $this->template[$post_name]['Default'] = preg_replace("/, $/","",$this->template[$post_name]['Default']); } } - - } @@ -246,7 +193,7 @@ class debconf $fn= "render_".$entry['Type']; $str = $this->$fn($entry); if(!empty($str)){ - $result.=$str."

 

"; + $result.=$str."
"; } } else { //php_error(E_WARNING, "An unknown type has been specified in the debconf template. Please fix."); @@ -264,12 +211,11 @@ class debconf function render_boolean($data) { - $post_name= $data['post_name']; $result=" -

".$data['Topic']."

".$data['Description']." +

".$data['Topic']."

".$data['Description']." "; @@ -295,10 +241,11 @@ class debconf { $post_name= $data['post_name']; if (preg_match('/\$\{/', $data['Choices'])){ + $data['Description'].= '

'._('This debconf question is dynamically generated during package installation and requires choosing between specific options which cannot be presented here. The entered text needs to be one of the valid choices in order to take effect.').''; $result= $this->render_string($data); } else { $choices= ""; - foreach (split(", ", $data['Choices']) as $choice){ + foreach (explode(", ", $data['Choices']) as $choice){ $choices[]= $choice; } @@ -306,13 +253,13 @@ class debconf $result=" -

".$data['Topic']."

".$data['Description']." +

".$data['Topic']."

".$data['Description']." "; - $defs = split(", ",$data['Default']); + $defs = explode(", ",$data['Default']); foreach($choices as $value){ if(in_array($value,$defs)){ $result.="\n".$value."
"; @@ -342,7 +289,7 @@ class debconf { $result= ""; $result.= ""; - $result.= "

".$data['Topic']."

".$data['Description']." 

"; + $result.= "

".$data['Topic']."

".$data['Description']." 

"; $result.= $data['Description']; $result.= ""; @@ -355,37 +302,36 @@ class debconf $post_name= $data['post_name']; if (preg_match('/\$\{/', $data['Choices'])){ - $choices= array("Need to use some text..."); + $result = $this->render_multiselect($data); } else { $choices= ""; - foreach (split(", ", $data['Choices']) as $choice){ + foreach (explode(", ", $data['Choices']) as $choice){ $choices[]= $choice; } - } - - $result=" - - - -

".$data['Topic']."

".$data['Description']." - - - "; + $result=" + + + +

".$data['Topic']."

".$data['Description']." + + + "; - foreach($choices as $value){ - if($data['Default'] == $value){ - $result.="\n".htmlentities($value)."
"; - }else{ - $result.="\n".htmlentities($value)."
"; + foreach($choices as $value){ + if($data['Default'] == $value){ + $result.="\n".htmlentities($value)."
"; + }else{ + $result.="\n".htmlentities($value)."
"; + } } - } - $result.= " - - - - "; + $result.= " + + + + "; + } return ($result); } @@ -396,7 +342,7 @@ class debconf $result= " -

".$data['Topic']."

".$data['Description']." +

".$data['Topic']."

".$data['Description']."