ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Core Class Reference
+ Collaboration diagram for Core:

Public Member Functions

 Core ($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.

Member Function Documentation

◆ _munge()

Core::_munge (   $munge)

Definition at line 535 of file Core.php.

536{
537 $munge = str_replace(">", ">", $munge);
538 $munge = str_replace("&lt;","<", $munge);
539
540 $inword = 0;
541 $currword = "";
542 $currchar = "";
543 $strout = "";
544 $lngth = strlen($munge);
545 if ($this->context->inselection || $this->context->lineselect) return $munge;
546 if (!$this->context->prepro)
547 {
548 for($i=0; $i<=$lngth; $i++)
549 {
550 $currchar = $munge[$i];
551 $delim = in_array($currchar, $this->highlightfile->delimiters);
552 if ($delim || $i==($lngth))
553 {
554 if ($inword)
555 {
556 $inword = 0;
557 $oldword = $currword;
558
559 $checkword = $oldword;
560 if ($this->highlightfile->nocase) $checkword = strtolower($checkword);
561 $currword = str_replace("<", "&lt;", $currword);
562 $currword = str_replace(">", "&gt;", $currword);
563 if (isset($this->context->validkeys[$checkword]))
564 {
565
566 if ($this->highlightfile->nocase) $checkword = $this->context->validkeys[$checkword];
567 $category = $this->highlightfile->keywords[$checkword];
568 $fontchunk = $this->context->category_parts[$category][0].$currword.$this->context->category_parts[$category][1];
569
570 if (
571 isset($this->highlightfile->linkscripts) &&
572 (
573 $code = call_user_method($this->highlightfile->linkscripts{$category}, $this->highlightfile, $oldword, $this->output_module)
574 ) != $oldword
575 )
576 {
577 $fontchunk = $code;
578 }
579 $strout .= $fontchunk;
580 }
581 else
582 $strout .= $currword;
583 }
584 $currchar = str_replace("<", "&lt;", $currchar);
585 $currchar = str_replace(">", "&gt;", $currchar);
586 $strout .= $currchar;
587 }
588 else
589 {
590 if ($inword)
591 {
592 $currword .= $currchar;
593 }
594 else
595 {
596 $inword = 1;
597 $currword = $currchar;
598 }
599 }
600 }
601 }
602 else
603 {
604 $strout = htmlentities($munge);
605 }
606
607 return $strout;
608}
$code
Definition: example_050.php:99

References $code.

Referenced by highlight_text().

+ Here is the caller graph for this function:

◆ _starts_with()

Core::_starts_with (   $text,
  $array 
)

Definition at line 616 of file Core.php.

617{
618
619 $ml = 0;
620 $curr = "";
621
622 foreach($array as $i)
623 {
624 $l = strlen($i);
625 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)))
626 {
627 if ($l>$ml)
628 {
629 $curr = substr($text, 0, $l);
630 $ml = $l;
631 }
632 }
633 }
634 return $curr;
635}
global $l
Definition: afr.php:30
$text

References $l, and $text.

Referenced by highlight_text().

+ Here is the caller graph for this function:

◆ Core()

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

Definition at line 29 of file Core.php.

30{
31 if (!isset($file)) $file = new HFile();
32 $this->zbuffer = false;
33 $this->buffer = false;
34 $this->highlightfile = $file;
35 $this->output_module = $outputmodule;
36}
print $file

References $file.

◆ get_stack()

Core::get_stack ( )

Definition at line 529 of file Core.php.

530{
531 return $this->contextstack;
532}

◆ highlight_text()

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

Definition at line 55 of file Core.php.

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

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

+ Here is the call graph for this function:

◆ load_file()

Core::load_file (   $filename)

Definition at line 41 of file Core.php.

42{
43 $filehandle = fopen ($filename, "r") or die("Could not open $filename for reading.");
44 $text = fread($filehandle, filesize($filename));
45 fclose($filehandle);
46 return $text;
47}
$filename
Definition: buildRTE.php:89

References $filename, and $text.

◆ set_stats()

Core::set_stats (   $statobj)

Definition at line 49 of file Core.php.

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

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