ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Core Class Reference
+ Collaboration diagram for Core:

Public Member Functions

 __construct ($file=undef, $outputmodule)
 
 load_file ($filename)
 
 set_stats ($statobj)
 
 highlight_text ($text, $contextstack=undef)
 
 get_stack ()
 
 _munge ($munge)
 
 _starts_with ($text, $array)
 

Detailed Description

Definition at line 26 of file Core.php.

Constructor & Destructor Documentation

◆ __construct()

Core::__construct (   $file = undef,
  $outputmodule 
)

Definition at line 28 of file Core.php.

References $file.

29  {
30  if (!isset($file)) {
31  $file = new HFile();
32  }
33  $this->zbuffer = false;
34  $this->buffer = false;
35  $this->highlightfile = $file;
36  $this->output_module = $outputmodule;
37  }
Definition: HFile.php:21
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file

Member Function Documentation

◆ _munge()

Core::_munge (   $munge)

Definition at line 492 of file Core.php.

References $code, $i, and array.

Referenced by highlight_text().

493  {
494  $munge = str_replace(">", ">", $munge);
495  $munge = str_replace("&lt;", "<", $munge);
496 
497  $inword = 0;
498  $currword = "";
499  $currchar = "";
500  $strout = "";
501  $lngth = strlen($munge);
502  if ($this->context->inselection || $this->context->lineselect) {
503  return $munge;
504  }
505  if (!$this->context->prepro) {
506  for ($i=0; $i<=$lngth; $i++) {
507  $currchar = $munge[$i];
508  $delim = in_array($currchar, $this->highlightfile->delimiters);
509  if ($delim || $i==($lngth)) {
510  if ($inword) {
511  $inword = 0;
512  $oldword = $currword;
513 
514  $checkword = $oldword;
515  if ($this->highlightfile->nocase) {
516  $checkword = strtolower($checkword);
517  }
518  $currword = str_replace("<", "&lt;", $currword);
519  $currword = str_replace(">", "&gt;", $currword);
520  if (isset($this->context->validkeys[$checkword])) {
521  if ($this->highlightfile->nocase) {
522  $checkword = $this->context->validkeys[$checkword];
523  }
524  $category = $this->highlightfile->keywords[$checkword];
525  $fontchunk = $this->context->category_parts[$category][0] . $currword . $this->context->category_parts[$category][1];
526 
527  if (
528  isset($this->highlightfile->linkscripts) &&
529  (
530  $code = call_user_func(array($this->highlightfile, $this->highlightfile->linkscripts{$category}), $oldword, $this->output_module)
531  //$code = call_user_method($this->highlightfile->linkscripts{$category}, $this->highlightfile, $oldword, $this->output_module)
532  ) != $oldword
533  ) {
534  $fontchunk = $code;
535  }
536  $strout .= $fontchunk;
537  } else {
538  $strout .= $currword;
539  }
540  }
541  $currchar = str_replace("<", "&lt;", $currchar);
542  $currchar = str_replace(">", "&gt;", $currchar);
543  $strout .= $currchar;
544  } else {
545  if ($inword) {
546  $currword .= $currchar;
547  } else {
548  $inword = 1;
549  $currword = $currchar;
550  }
551  }
552  }
553  } else {
554  $strout = htmlentities($munge);
555  }
556 
557  return $strout;
558  }
$code
Definition: example_050.php:99
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ _starts_with()

Core::_starts_with (   $text,
  $array 
)

Definition at line 566 of file Core.php.

References $i, $l, and $text.

Referenced by highlight_text().

567  {
568  $ml = 0;
569  $curr = "";
570 
571  foreach ($array as $i) {
572  $l = strlen($i);
573  if (((!$this->highlightfile->nocase && substr($text, 0, $l)==$i) || ($this->highlightfile->nocase && strtolower(substr($text, 0, $l))==strtolower($i))) && ($text[$l]==" " || $l==1 || $text[$l]=="\n" || $text[$l]=="\t" || $text[$l]=="." || $text[$l]==";" || $l==strlen($text))) {
574  if ($l>$ml) {
575  $curr = substr($text, 0, $l);
576  $ml = $l;
577  }
578  }
579  }
580  return $curr;
581  }
$text
Definition: errorreport.php:18
global $l
Definition: afr.php:30
$i
Definition: disco.tpl.php:19
+ Here is the caller graph for this function:

◆ get_stack()

Core::get_stack ( )

Definition at line 486 of file Core.php.

487  {
488  return $this->contextstack;
489  }

◆ highlight_text()

Core::highlight_text (   $text,
  $contextstack = undef 
)

Definition at line 56 of file Core.php.

References $BEAUT_PATH, $i, $l, $out, $text, _munge(), _starts_with(), and array.

57  {
58  global $BEAUT_PATH;
59  if (isset($contextstack) && is_array($contextstack)) {
60  $this->contextstack = $contextstack;
61  $this->context = array_pop($contextstack);
62  $this->context->inwhitespace = 0;
63  } else {
64  $this->context = new Context();
65  $this->context->from_language($this->highlightfile, $this->output_module);
66  $this->contextstack = array();
67  }
68  array_push($this->contextstack, $this->context);
69  $this->langstack = array();
70 
71  if (isset($this->highlightfile->zones)) {
72  // Create the hash mapping from start tag to language, and put together a hash to give
73  // the possible endings for a start tag.
74  $this->starttags = array();
75  $this->endtags = array();
76  $this->starttaglengths = array();
77  foreach ($this->highlightfile->zones as $zone) {
78  $this->startmap[$zone[0]] = $zone[2];
79  array_push($this->starttags, $zone[0]);
80  if (!isset($this->endtags[$zone[0]])) {
81  $this->endtags[$zone[0]] = array();
82  }
83  array_push($this->endtags[$zone[0]], $zone[1]);
84  $this->starttaglengths[$zone[0]] = strlen($zone[0]);
85  }
86  $this->endtaglist = array();
87  $this->langcache = array();
88  }
89 
90 
91  // Get the lines.
92  $arr = preg_split("/\n/", $text);
93  $aln = sizeof($arr);
94 
95  if (isset($this->context->code_parts[0])) {
96  $out.= $this->context->code_parts[0];
97  }
98  for ($i=0; $i<$aln; $i++) {
99  $this->context->prepro = 0;
100  $line = $arr[$i];
101  if ($this->context->preprolength>0 && substr($line, 0, $this->context->preprolength)==$this->highlightfile->prepro) {
102  $out.= $this->context->prepro_parts[0];
103  $this->context->prepro = 1;
104  }
105 
106 
107  $this->context->inwhitespace = 1;
108 
109 
110  $this->context->incomment = 0;
111  // Handle selected lines.
112  if (isset($this->highlightfile->lineselect) && !$this->context->inselection && substr($line, 0, strlen($this->highlightfile->lineselect))==$this->highlightfile->lineselect) {
113  $out.= $this->context->select_parts[0];
114  $line = substr($line, strlen($this->highlightfile->lineselect));
115  $this->context->lineselect = 1;
116  }
117 
118  // Strip leading and trailing spaces
119  if ($this->highlightfile->notrim==0) {
120  $line = trim($line);
121  }
122 
123  $lineout = "";
124  $lineorig = $line;
125  // Print out the current indent.
126  $sw = $this->_starts_with($lineorig, $this->highlightfile->unindent);
127  if ($lineorig != "") {
128  if ($this->context->ind>0 && $sw!="") {
129  //$lineout = str_repeat(" ", ($this->context->ind-1));
130  $lineout = str_repeat("\t", ($this->context->ind-1));
131  } else {
132  $lineout = str_repeat("\t", $this->context->ind);
133  }
134  }
135  $ln = strlen($lineorig);
136  for ($j=0; $j<$ln; $j++) {
137  $currchar = $lineorig[$j];
138  //print $currchar;
139  // Handle opening selection blocks.
140  if (isset($this->highlightfile->selecton) && !$this->context->inselection &&
141  !$this->context->inquote && !$this->context->inbcomment &&
142  substr($line, $j, strlen($this->highlightfile->selecton))==$this->highlightfile->selecton) {
143  //print "01";
144  $lineout = $this->_munge($lineout) . $this->context->select_parts[0];
145  $out.= $lineout;
146  $lineout = "";
147  $this->context->inselection = 1;
148  $j+= strlen($this->highlightfile->selecton)-1;
149  continue;
150  }
151  // Handle closing selection blocks.
152  if (isset($this->highlightfile->selectoff) && $this->context->inselection &&
153  substr($line, $j, strlen($this->highlightfile->selectoff))==$this->highlightfile->selectoff) {
154  //print "02";
155  $lineout.=$this->context->select_parts[1];
156  $out.= $lineout;
157  $lineout = "";
158  $this->context->inselection = 0;
159  $j+= strlen($this->highlightfile->selectoff);
160  continue;
161  }
162  // Handle line comments. This is made slightly faster by going straight to
163  // the next line - as nothing else can be done.
164  if (!$this->context->lineselect && !$this->context->inselection && !$this->context->inquote && !$this->context->incomment && !($this->highlightfile->perl && $j>0 && $line[$j-1]=="$")) {
165  //print "03";
166  $currmax = 0;
167  foreach ($this->highlightfile->linecommenton as $l) {
168  if ($l[0] != $currchar) {
169  continue;
170  }
171  $lln = $this->context->lcolengths[$l];
172  if (substr($line, $j, $lln)==$l) {
173  if ($lln > $currmax) {
174  $lnc = $l;
175  $currmax = $lln;
176  }
177  }
178  }
179 
180  if ($currmax != 0) {
181  //print "04";
182 
183  $line = substr($line, $j);
184  $lineout = $this->_munge($lineout);
185  $line = htmlentities($line);
186  $out.= $lineout;
187  if ($this->context->prepro) {
188  $out.= $this->context->prepro_parts[1];
189  $this->context->prepro = 0;
190  }
191  $out.= $this->context->linecomment_parts[0] . $line;
192  if (isset($this->statobj) && $this->statobj->harvest_comments) {
193  $this->statobj->comment_cache .= " " . substr($line, $lncl);
194  }
195  $lineout = "";
196  $this->context->incomment = 1;
197  $j = $ln + 1;
198  continue;
199  }
200  }
201 
202  // Handle opening block comments. Sadly this can't be done quickly (like with
203  // line comments) as we may have 'foo /* bar */ foo'.
204  if (!$this->context->lineselect && !$this->context->inselection && !$this->context->inquote && !$this->context->inbcomment && in_array($currchar, $this->context->startingbkonchars)) {
205  //print "05";
206  $currmax = 0;
207  foreach ($this->highlightfile->blockcommenton as $bo) {
208  if ($bo[0] != $currchar) {
209  continue;
210  }
211  $boln = $this->context->bcolengths[$bo];
212  if (substr($line, $j, $boln)==$bo) {
213  if ($boln > $currmax) {
214  //print "06";
215  $bkc = $bo;
216  $bkcl = $boln;
217  $currmax = $boln;
218  }
219  }
220  }
221 
222  if ($currmax != 0) {
223  //print "07";
224  if ($this->prepro) {
225  $out.= $this->context->prepro_parts[1];
226  $this->prepro = 0;
227  }
228  $this->context->closingstrings = $this->context->bcomatches[$bkc];
229  $lineout = $this->_munge($lineout);
230  $bkcout = str_replace(">", "&gt;", $bkc);
231  $bkcout = str_replace("<", "&lt;", $bkcout);
232  $out.= $lineout;
233  $out.= $this->context->blockcomment_parts[0] . $bkcout;
234  $lineout = "";
235  $this->context->inbcomment = 1;
236  $j += $bkcl-1;
237  continue;
238  }
239  }
240  // Handle closing comments.
241  if (!$this->context->lineselect && !$this->context->inselection && !$this->context->inquote && $this->context->inbcomment) {
242  //print "08";
243  $currmax = 0;
244  foreach ($this->context->closingstrings as $bf) {
245  if ($bf[0] != $currchar) {
246  continue;
247  }
248  $bfln = $this->context->bcflengths[$bf];
249  if (substr($line, $j, $bfln)==$bf) {
250  if ($bfln > $currmax) {
251  $bku = $bf;
252  $bkul = $bfln;
253  $currmax = $bfln;
254  }
255  }
256  }
257 
258  if ($currmax != 0) {
259  //print "09";
260  $bkuout = str_replace(">", "&gt;", $bku);
261  $bkuout = str_replace("<", "&lt;", $bkuout);
262  $lineout .= $bkuout . $this->context->blockcomment_parts[1];
263 
264  $out.= $lineout;
265  $lineout = "";
266  $this->context->inbcomment = 0;
267  $j += $bkul-1;
268  continue;
269  }
270  }
271  if (isset($this->highlightfile->zones) && !$this->context->inbcomment && !$this->context->incomment && !$this->context->inquote) {
272  //print "10";
273  $startcurrmax = 0;
274  foreach ($this->starttags as $starttag) {
275  if ($starttag[0] != $currchar) {
276  continue;
277  } // Avoid doing substr.
278  $starttagln = $this->starttaglengths[$starttag];
279 
280  if (substr($line, $j, $starttagln)==$starttag) {
281  if ($starttagln > $startcurrmax) {
282  $startcurrtag = $starttag;
283  $startcurrmax = $starttagln;
284  }
285  }
286  }
287  if ($startcurrmax != 0) {
288  //print "11";
289  $tagout = str_replace(">", "&gt;", $startcurrtag);
290  $tagout = str_replace("<", "&lt;", $tagout);
291  $out.= ltrim($lineout); // Sane? --moj
292  array_push($this->langstack, $this->highlightfile);
293  array_push($this->contextstack, $this->context);
294  $out.= "$tagout";
295  require_once $BEAUT_PATH . "/HFile/" . $this->startmap[$startcurrtag] . ".php";
296  $this->endtaglist = $this->endtags[$startcurrtag];
297  if (isset($this->langcache[$startcurrtag])) {
298  $this->highlightfile = $this->langcache[$startcurrtag];
299  } else {
300  $this->highlightfile = new $this->startmap[$startcurrtag]();
301  $this->langcache[$startcurrtag] = $this->highlightfile;
302  }
303  $this->context = new Context();
304  $this->context->from_language($this->highlightfile, $this->output_module);
305  $lineout = "";
306  $j += $startcurrmax-1;
307  continue;
308  }
309 
310  $endcurrmax = 0;
311  foreach ($this->endtaglist as $endtag) {
312  if ($endtag[0] != $currchar) {
313  continue;
314  } // Avoid doing substr.
315  $endtagln = strlen($endtag);
316  if (substr($line, $j, $endtagln)==$endtag) {
317  if ($endtagln > $endcurrmax) {
318  $endcurrtag = $endtag;
319  $endcurrmax = $endtagln;
320  }
321  }
322  }
323  if ($endcurrmax!=0) {
324  //print "12";
325  $tagout = str_replace(">", "&gt;", $endcurrtag);
326  $tagout = str_replace("<", "&lt;", $tagout);
327 
328  $lineout .= "$tagout";
329  $out.= $lineout;
330  $lineout = "";
331  $this->highlightfile = array_pop($this->langstack);
332  $this->context = array_pop($this->contextstack);
333  $this->endtaglist = array();
334  $j += $endcurrmax;
335  continue;
336  }
337  }
338  // If we're in a comment, skip keyword checking, cache the comments, and go
339  // to the next char.
340  if ($this->context->incomment || $this->context->inbcomment) {
341  if ($this->context->inbcomment) {
342  if ($currchar == "<") {
343  $currchar = "&lt;";
344  } elseif ($currchar == ">") {
345  $currchar = "&gt;";
346  } elseif ($currchar == "&") {
347  $currchar = "&amp;";
348  }
349  }
350  //print "13";
351  $lineout .= $currchar;
352  if ($this->context->newline) {
353  if (isset($this->statobj) && $this->statobj->harvest_comments) {
354  $this->statobj->comment_cache .= " ";
355  }
356  $this->context->newline = 0;
357  }
358  if (isset($this->statobj) && $this->statobj->harvest_comments) {
359  $this->statobj->comment_cache .= $currchar;
360  }
361  continue;
362  }
363 
364  // Indent has to be either preceded by, or be, a delimiter.
365  $delim = ($j==0 || in_array($currchar, $this->context->alldelims) || ($j>0 && in_array($lineorig[$j-1], $this->context->alldelims)));
366 
367  // Handle quotes.
368  if (!$this->context->lineselect && !$this->context->inselection && !$this->context->escaping &&
369  ((in_array($currchar, (array) $this->highlightfile->stringchars) && $this->context->inquote && $currchar==$this->context->currquotechar) || (in_array($currchar, (array) $this->highlightfile->stringchars) && !$this->context->inquote))) {
370 
371 //print "14:$currchar";
372  // First quote, so go blue.
373  if (!$this->context->escaping && isset($this->context->inquote) && !$this->context->inquote) {
374  //print "15";
375  $lineout = $this->_munge($lineout);
376  $out.= $lineout;
377  $this->context->inquote = 1;
378  if (isset($this->statobj) && $this->statobj->harvest_strings) {
379  $this->string_cache.=" ";
380  }
381  if ($this->context->prepro) {
382  $lineout = $this->context->prepro_parts[1] . $currchar . $this->context->quote_parts[0];
383  } else {
384  $out.= $currchar . $this->context->quote_parts[0];
385  $lineout = "";
386  }
387  $this->context->currquotechar = $currchar;
388  }
389  // Last quote, so turn off font colour.
390  elseif ($this->context->inquote && !$this->context->escaping && $currchar == $this->context->currquotechar) {
391  //print "16";
392  $this->context->inquote = 0;
393  if ($this->context->prepro) {
394  $lineout .= $this->context->quote_parts[1] . $this->context->prepro_parts[0] . $lineorig[$j];
395  } else {
396  $lineout .= $this->context->quote_parts[1] . $lineorig[$j];
397  }
398  $out.= $lineout;
399  $lineout = "";
400  $this->context->currquotechar = "";
401  }
402  }
403  // If we've got an indent character, increase the level, and add an indent.
404  elseif (!$this->context->inselection && $delim && !$this->context->inquote && ($stri=$this->_starts_with(substr($line, $j), $this->highlightfile->indent))!="") {
405  //print "17";
406  if (!$this->context->inwhitespace) {
407  //$lineout .= str_repeat(" ", $this->context->ind);
408  $lineout .= str_repeat("\t", $this->context->ind);
409  }
410  $lineout .= $stri;
411  $this->context->ind++;
412  $j += strlen($stri)-1;
413  }
414  // If we've got an unindent (and we are indented), go back a level.
415  elseif (!$this->context->inselection && $delim && $this->context->ind>0 && !$this->context->inquote && ($stru=$this->_starts_with(substr($line, $j), $this->highlightfile->unindent))!="") {
416  //print "18";
417  $this->context->ind--;
418 
419  if (!$this->context->inwhitespace) {
420  //$lineout .= str_repeat(" ", $this->context->ind);
421  $lineout .= str_repeat("\t", $this->context->ind);
422  }
423  $lineout .= $stru;
424 
425  $j += strlen($stru)-1;
426  }
427  // Add the characters to the output, and cache strings.
428  elseif (!$this->context->inwhitespace || $currchar != " " || $currchar != "\t") {
429  //print "19";
430  if ($this->context->inquote && isset($this->statobj) && $this->statobj->harvest_strings) {
431  $this->statobj->string_cache .=$currchar;
432  }
433  $lineout .= htmlentities($currchar);
434  }
435  if ($this->context->inquote && $this->context->escaping) {
436  //print "20";
437  $this->context->escaping = 0;
438  } elseif ($this->context->inquote && $currchar == $this->highlightfile->escchar && !$this->context->escaping) {
439  //print "21";
440  $this->context->escaping = 1;
441  }
442  }
443  if ($currchar != " " && $currchar != "\t") {
444  $this->context->inwhitespace = 0;
445  }
446  if (!$this->context->incomment && !$this->context->inbcomment && !$this->context->inquote) {
447  $lineout = $this->_munge($lineout);
448  }
449  if ($i<($aln-1)) {
450  if ($this->context->prepro) {
451  $lineout .= $this->context->prepro_parts[1];
452  }
453  }
454  // Close any hanging font tags.
455  if ($this->context->incomment) {
456  $out.= $this->context->linecomment_parts[1];
457  }
458  if ($i<($aln-1)) {
459  $lineout .="\n";
460  }
461  if ($this->context->lineselect) {
462  $lineout.= $this->context->select_parts[1];
463  }
464  $out.= $lineout;
465  $this->context->newline = 1;
466  $this->context->lineselect = 0;
467  }
468  // If we've finished, and are still in a comment, close the font tag.
469  if ($this->context->incomment) {
470  $out.= $this->context->linecomment_parts[1];
471  } elseif ($this->context->inbcomment) {
472  $out.= $this->context->blockcomment_parts[1];
473  } elseif ($this->context->inselection) {
474  $out.= $this->context->select_parts[1];
475  }
476  if (isset($this->context->code_parts[1])) {
477  $out.= $this->context->code_parts[1];
478  }
479 
480  $pad = str_repeat(" ", $this->highlightfile->indent_depth);
481  $out = str_replace("\t", $pad, $out);
482 
483  return $out;
484  }
$BEAUT_PATH
Definition: Core.php:21
$text
Definition: errorreport.php:18
_starts_with($text, $array)
Definition: Core.php:566
Create styles array
The data for the language used.
_munge($munge)
Definition: Core.php:492
global $l
Definition: afr.php:30
$i
Definition: disco.tpl.php:19
+ Here is the call graph for this function:

◆ load_file()

Core::load_file (   $filename)

Definition at line 42 of file Core.php.

References $filename, and $text.

43  {
44  $filehandle = fopen($filename, "r") or die("Could not open $filename for reading.");
45  $text = fread($filehandle, filesize($filename));
46  fclose($filehandle);
47  return $text;
48  }
for( $i=1;$i< 200;$i++)
Holds the type of the event to listen for.
Definition: 04printing.php:58
$text
Definition: errorreport.php:18

◆ set_stats()

Core::set_stats (   $statobj)

Definition at line 50 of file Core.php.

51  {
52  $this->statobj = $statobj;
53  }

The documentation for this class was generated from the following file: