TPSection.php
Go to the documentation of this file.00001 <?php
00016 class TPSection {
00018 public $id;
00020 public $name;
00022 public $text;
00024 public $type;
00026 public $oldText;
00027
00032 public function getText() {
00033 return $this->text;
00034 }
00035
00040 public function getTextForTrans() {
00041 $re = '~<tvar\|([^>]+)>(.*?)</>~u';
00042
00043 return preg_replace( $re, '\2', $this->text );
00044 }
00045
00050 public function getMarkedText() {
00051 $id = isset( $this->name ) ? $this->name : $this->id;
00052 $header = "<!--T:{$id}-->";
00053 $re = '~^(=+.*?=+\s*?$)~m';
00054 $rep = "\\1 $header";
00055 $count = 0;
00056
00057 $text = preg_replace( $re, $rep, $this->text, 1, $count );
00058
00059 if ( $count === 0 ) {
00060 $text = $header . "\n" . $this->text;
00061 }
00062
00063 return $text;
00064 }
00065
00070 public function getOldText() {
00071 return isset( $this->oldText ) ? $this->oldText : $this->text;
00072 }
00073
00079 public function getVariables() {
00080 $re = '~<tvar\|([^>]+)>(.*?)</>~u';
00081 $matches = array();
00082 preg_match_all( $re, $this->text, $matches, PREG_SET_ORDER );
00083 $vars = array();
00084
00085 foreach ( $matches as $m ) {
00086 $vars['$' . $m[1]] = $m[2];
00087 }
00088
00089 return $vars;
00090 }
00091 }