00001 <?php 00012 require_once("Model.php"); 00013 00015 class Transform extends Model { 00021 public function Transform ($conf = NULL) { 00022 Model::Model($conf); 00023 if ($this->get("Transform_Delimiter") !== false) { 00024 $this->set("Transform_OpenDelimiter","@"); 00025 $this->set("Transform_CloseDelimiter","@"); 00026 } else { 00027 if ($this->get("Transform_OpenDelimiter") === false) { 00028 $this->set("Transform_OpenDelimiter","@"); 00029 } 00030 if ($this->get("Transform_CloseDelimiter") === false) { 00031 $this->set("Transform_CloseDelimiter","@"); 00032 } 00033 } 00034 } 00035 00042 public function TransformThis($data, $text) { 00043 if ($this->get("Transform_Delimiter") !== false) { 00044 $open_token = $this->get("Transform_Delimiter"); 00045 $close_token = $this->get("Transform_Delimiter"); 00046 } else { 00047 $open_token = $this->get("Transform_OpenDelimiter"); 00048 $close_token = $this->get("Transform_CloseDelimiter"); 00049 } 00050 $target = array(); 00051 $replacement = array(); 00052 foreach ($data as $key => $value) { 00053 $target[] = $open_token.trim($key).$close_token; 00054 isset($value) ? $replacement[] = $value : $replacement[] = ""; 00055 } 00056 return str_replace($target,$replacement, $text); 00057 } 00058 } 00059 00060 ?>