Ingen beskrivning

cellmap.cls.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. <?php
  2. /**
  3. * @package dompdf
  4. * @link http://dompdf.github.com/
  5. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  6. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  7. */
  8. /**
  9. * Maps table cells to the table grid.
  10. *
  11. * This class resolves borders in tables with collapsed borders and helps
  12. * place row & column spanned table cells.
  13. *
  14. * @access private
  15. * @package dompdf
  16. */
  17. class Cellmap
  18. {
  19. /**
  20. * Border style weight lookup for collapsed border resolution.
  21. *
  22. * @var array
  23. */
  24. static protected $_BORDER_STYLE_SCORE = array(
  25. "inset" => 1,
  26. "groove" => 2,
  27. "outset" => 3,
  28. "ridge" => 4,
  29. "dotted" => 5,
  30. "dashed" => 6,
  31. "solid" => 7,
  32. "double" => 8,
  33. "hidden" => 9,
  34. "none" => 0,
  35. );
  36. /**
  37. * The table object this cellmap is attached to.
  38. *
  39. * @var Table_Frame_Decorator
  40. */
  41. protected $_table;
  42. /**
  43. * The total number of rows in the table
  44. *
  45. * @var int
  46. */
  47. protected $_num_rows;
  48. /**
  49. * The total number of columns in the table
  50. *
  51. * @var int
  52. */
  53. protected $_num_cols;
  54. /**
  55. * 2D array mapping <row,column> to frames
  56. *
  57. * @var Frame[][]
  58. */
  59. protected $_cells;
  60. /**
  61. * 1D array of column dimensions
  62. *
  63. * @var array
  64. */
  65. protected $_columns;
  66. /**
  67. * 1D array of row dimensions
  68. *
  69. * @var array
  70. */
  71. protected $_rows;
  72. /**
  73. * 2D array of border specs
  74. *
  75. * @var array
  76. */
  77. protected $_borders;
  78. /**
  79. * 1D Array mapping frames to (multiple) <row, col> pairs, keyed on frame_id.
  80. *
  81. * @var Frame[]
  82. */
  83. protected $_frames;
  84. /**
  85. * Current column when adding cells, 0-based
  86. *
  87. * @var int
  88. */
  89. private $__col;
  90. /**
  91. * Current row when adding cells, 0-based
  92. *
  93. * @var int
  94. */
  95. private $__row;
  96. /**
  97. * Tells wether the columns' width can be modified
  98. *
  99. * @var bool
  100. */
  101. private $_columns_locked = false;
  102. /**
  103. * Tells wether the table has table-layout:fixed
  104. *
  105. * @var bool
  106. */
  107. private $_fixed_layout = false;
  108. //........................................................................
  109. function __construct(Table_Frame_Decorator $table)
  110. {
  111. $this->_table = $table;
  112. $this->reset();
  113. }
  114. function __destruct()
  115. {
  116. clear_object($this);
  117. }
  118. //........................................................................
  119. function reset()
  120. {
  121. $this->_num_rows = 0;
  122. $this->_num_cols = 0;
  123. $this->_cells = array();
  124. $this->_frames = array();
  125. if (!$this->_columns_locked) {
  126. $this->_columns = array();
  127. }
  128. $this->_rows = array();
  129. $this->_borders = array();
  130. $this->__col = $this->__row = 0;
  131. }
  132. //........................................................................
  133. function lock_columns()
  134. {
  135. $this->_columns_locked = true;
  136. }
  137. function is_columns_locked()
  138. {
  139. return $this->_columns_locked;
  140. }
  141. function set_layout_fixed($fixed)
  142. {
  143. $this->_fixed_layout = $fixed;
  144. }
  145. function is_layout_fixed()
  146. {
  147. return $this->_fixed_layout;
  148. }
  149. function get_num_rows()
  150. {
  151. return $this->_num_rows;
  152. }
  153. function get_num_cols()
  154. {
  155. return $this->_num_cols;
  156. }
  157. function &get_columns()
  158. {
  159. return $this->_columns;
  160. }
  161. function set_columns($columns)
  162. {
  163. $this->_columns = $columns;
  164. }
  165. function &get_column($i)
  166. {
  167. if (!isset($this->_columns[$i])) {
  168. $this->_columns[$i] = array(
  169. "x" => 0,
  170. "min-width" => 0,
  171. "max-width" => 0,
  172. "used-width" => null,
  173. "absolute" => 0,
  174. "percent" => 0,
  175. "auto" => true,
  176. );
  177. }
  178. return $this->_columns[$i];
  179. }
  180. function &get_rows()
  181. {
  182. return $this->_rows;
  183. }
  184. function &get_row($j)
  185. {
  186. if (!isset($this->_rows[$j])) {
  187. $this->_rows[$j] = array(
  188. "y" => 0,
  189. "first-column" => 0,
  190. "height" => null,
  191. );
  192. }
  193. return $this->_rows[$j];
  194. }
  195. function get_border($i, $j, $h_v, $prop = null)
  196. {
  197. if (!isset($this->_borders[$i][$j][$h_v])) {
  198. $this->_borders[$i][$j][$h_v] = array(
  199. "width" => 0,
  200. "style" => "solid",
  201. "color" => "black",
  202. );
  203. }
  204. if (isset($prop)) {
  205. return $this->_borders[$i][$j][$h_v][$prop];
  206. }
  207. return $this->_borders[$i][$j][$h_v];
  208. }
  209. function get_border_properties($i, $j)
  210. {
  211. return array(
  212. "top" => $this->get_border($i, $j, "horizontal"),
  213. "right" => $this->get_border($i, $j + 1, "vertical"),
  214. "bottom" => $this->get_border($i + 1, $j, "horizontal"),
  215. "left" => $this->get_border($i, $j, "vertical"),
  216. );
  217. }
  218. //........................................................................
  219. function get_spanned_cells(Frame $frame)
  220. {
  221. $key = $frame->get_id();
  222. if (!isset($this->_frames[$key])) {
  223. throw new DOMPDF_Exception("Frame not found in cellmap");
  224. }
  225. return $this->_frames[$key];
  226. }
  227. function frame_exists_in_cellmap(Frame $frame)
  228. {
  229. $key = $frame->get_id();
  230. return isset($this->_frames[$key]);
  231. }
  232. function get_frame_position(Frame $frame)
  233. {
  234. global $_dompdf_warnings;
  235. $key = $frame->get_id();
  236. if (!isset($this->_frames[$key])) {
  237. throw new DOMPDF_Exception("Frame not found in cellmap");
  238. }
  239. $col = $this->_frames[$key]["columns"][0];
  240. $row = $this->_frames[$key]["rows"][0];
  241. if (!isset($this->_columns[$col])) {
  242. $_dompdf_warnings[] = "Frame not found in columns array. Check your table layout for missing or extra TDs.";
  243. $x = 0;
  244. } else {
  245. $x = $this->_columns[$col]["x"];
  246. }
  247. if (!isset($this->_rows[$row])) {
  248. $_dompdf_warnings[] = "Frame not found in row array. Check your table layout for missing or extra TDs.";
  249. $y = 0;
  250. } else {
  251. $y = $this->_rows[$row]["y"];
  252. }
  253. return array($x, $y, "x" => $x, "y" => $y);
  254. }
  255. function get_frame_width(Frame $frame)
  256. {
  257. $key = $frame->get_id();
  258. if (!isset($this->_frames[$key])) {
  259. throw new DOMPDF_Exception("Frame not found in cellmap");
  260. }
  261. $cols = $this->_frames[$key]["columns"];
  262. $w = 0;
  263. foreach ($cols as $i) {
  264. $w += $this->_columns[$i]["used-width"];
  265. }
  266. return $w;
  267. }
  268. function get_frame_height(Frame $frame)
  269. {
  270. $key = $frame->get_id();
  271. if (!isset($this->_frames[$key])) {
  272. throw new DOMPDF_Exception("Frame not found in cellmap");
  273. }
  274. $rows = $this->_frames[$key]["rows"];
  275. $h = 0;
  276. foreach ($rows as $i) {
  277. if (!isset($this->_rows[$i])) {
  278. throw new Exception("The row #$i could not be found, please file an issue in the tracker with the HTML code");
  279. }
  280. $h += $this->_rows[$i]["height"];
  281. }
  282. return $h;
  283. }
  284. //........................................................................
  285. function set_column_width($j, $width)
  286. {
  287. if ($this->_columns_locked) {
  288. return;
  289. }
  290. $col = &$this->get_column($j);
  291. $col["used-width"] = $width;
  292. $next_col = &$this->get_column($j + 1);
  293. $next_col["x"] = $next_col["x"] + $width;
  294. }
  295. function set_row_height($i, $height)
  296. {
  297. $row = &$this->get_row($i);
  298. if ($row["height"] !== null && $height <= $row["height"]) {
  299. return;
  300. }
  301. $row["height"] = $height;
  302. $next_row = &$this->get_row($i + 1);
  303. $next_row["y"] = $row["y"] + $height;
  304. }
  305. //........................................................................
  306. protected function _resolve_border($i, $j, $h_v, $border_spec)
  307. {
  308. $n_width = $border_spec["width"];
  309. $n_style = $border_spec["style"];
  310. if (!isset($this->_borders[$i][$j][$h_v])) {
  311. $this->_borders[$i][$j][$h_v] = $border_spec;
  312. return $this->_borders[$i][$j][$h_v]["width"];
  313. }
  314. $border = &$this->_borders[$i][$j][$h_v];
  315. $o_width = $border["width"];
  316. $o_style = $border["style"];
  317. if (($n_style === "hidden" ||
  318. $n_width > $o_width ||
  319. $o_style === "none")
  320. or
  321. ($o_width == $n_width &&
  322. in_array($n_style, self::$_BORDER_STYLE_SCORE) &&
  323. self::$_BORDER_STYLE_SCORE[$n_style] > self::$_BORDER_STYLE_SCORE[$o_style])
  324. ) {
  325. $border = $border_spec;
  326. }
  327. return $border["width"];
  328. }
  329. //........................................................................
  330. function add_frame(Frame $frame)
  331. {
  332. $style = $frame->get_style();
  333. $display = $style->display;
  334. $collapse = $this->_table->get_style()->border_collapse == "collapse";
  335. // Recursively add the frames within tables, table-row-groups and table-rows
  336. if (
  337. $display === "table-row" ||
  338. $display === "table" ||
  339. $display === "inline-table" ||
  340. in_array($display, Table_Frame_Decorator::$ROW_GROUPS)
  341. ) {
  342. $start_row = $this->__row;
  343. foreach ($frame->get_children() as $child) {
  344. $this->add_frame($child);
  345. }
  346. if ($display === "table-row") {
  347. $this->add_row();
  348. }
  349. $num_rows = $this->__row - $start_row - 1;
  350. $key = $frame->get_id();
  351. // Row groups always span across the entire table
  352. $this->_frames[$key]["columns"] = range(0, max(0, $this->_num_cols - 1));
  353. $this->_frames[$key]["rows"] = range($start_row, max(0, $this->__row - 1));
  354. $this->_frames[$key]["frame"] = $frame;
  355. if ($display !== "table-row" && $collapse) {
  356. $bp = $style->get_border_properties();
  357. // Resolve the borders
  358. for ($i = 0; $i < $num_rows + 1; $i++) {
  359. $this->_resolve_border($start_row + $i, 0, "vertical", $bp["left"]);
  360. $this->_resolve_border($start_row + $i, $this->_num_cols, "vertical", $bp["right"]);
  361. }
  362. for ($j = 0; $j < $this->_num_cols; $j++) {
  363. $this->_resolve_border($start_row, $j, "horizontal", $bp["top"]);
  364. $this->_resolve_border($this->__row, $j, "horizontal", $bp["bottom"]);
  365. }
  366. }
  367. return;
  368. }
  369. $node = $frame->get_node();
  370. /* Este cambio lo hice yo, Gabriel
  371. // Determine where this cell is going
  372. $colspan = $node->getAttribute("colspan");
  373. $rowspan = $node->getAttribute("rowspan");
  374. if ( !$colspan ) {
  375. $colspan = 1;
  376. $node->setAttribute("colspan",1);
  377. }
  378. if ( !$rowspan ) {
  379. $rowspan = 1;
  380. $node->setAttribute("rowspan",1);
  381. }*/
  382. if (method_exists($node, 'getAttribute')) {
  383. $colspan = $node->getAttribute("colspan");
  384. $rowspan = $node->getAttribute("rowspan");
  385. } else {
  386. $colspan = false;
  387. $rowspan = false;
  388. }
  389. if (!$colspan) {
  390. $colspan = 1;
  391. if (method_exists($node, 'setAttribute')) {
  392. $node->setAttribute("colspan", 1);
  393. }
  394. }
  395. if (!$rowspan) {
  396. $rowspan = 1;
  397. if (method_exists($node, 'setAttribute')) {
  398. $node->setAttribute("rowspan", 1);
  399. }
  400. }
  401. $key = $frame->get_id();
  402. $bp = $style->get_border_properties();
  403. // Add the frame to the cellmap
  404. $max_left = $max_right = 0;
  405. // Find the next available column (fix by Ciro Mondueri)
  406. $ac = $this->__col;
  407. while (isset($this->_cells[$this->__row][$ac])) {
  408. $ac++;
  409. }
  410. $this->__col = $ac;
  411. // Rows:
  412. for ($i = 0; $i < $rowspan; $i++) {
  413. $row = $this->__row + $i;
  414. $this->_frames[$key]["rows"][] = $row;
  415. for ($j = 0; $j < $colspan; $j++) {
  416. $this->_cells[$row][$this->__col + $j] = $frame;
  417. }
  418. if ($collapse) {
  419. // Resolve vertical borders
  420. $max_left = max($max_left, $this->_resolve_border($row, $this->__col, "vertical", $bp["left"]));
  421. $max_right = max($max_right, $this->_resolve_border($row, $this->__col + $colspan, "vertical", $bp["right"]));
  422. }
  423. }
  424. $max_top = $max_bottom = 0;
  425. // Columns:
  426. for ($j = 0; $j < $colspan; $j++) {
  427. $col = $this->__col + $j;
  428. $this->_frames[$key]["columns"][] = $col;
  429. if ($collapse) {
  430. // Resolve horizontal borders
  431. $max_top = max($max_top, $this->_resolve_border($this->__row, $col, "horizontal", $bp["top"]));
  432. $max_bottom = max($max_bottom, $this->_resolve_border($this->__row + $rowspan, $col, "horizontal", $bp["bottom"]));
  433. }
  434. }
  435. $this->_frames[$key]["frame"] = $frame;
  436. // Handle seperated border model
  437. if (!$collapse) {
  438. list($h, $v) = $this->_table->get_style()->border_spacing;
  439. // Border spacing is effectively a margin between cells
  440. $v = $style->length_in_pt($v) / 2;
  441. $h = $style->length_in_pt($h) / 2;
  442. $style->margin = "$v $h";
  443. // The additional 1/2 width gets added to the table proper
  444. } else {
  445. // Drop the frame's actual border
  446. $style->border_left_width = $max_left / 2;
  447. $style->border_right_width = $max_right / 2;
  448. $style->border_top_width = $max_top / 2;
  449. $style->border_bottom_width = $max_bottom / 2;
  450. $style->margin = "none";
  451. }
  452. if (!$this->_columns_locked) {
  453. // Resolve the frame's width
  454. if ($this->_fixed_layout) {
  455. list($frame_min, $frame_max) = array(0, 10e-10);
  456. } else {
  457. list($frame_min, $frame_max) = $frame->get_min_max_width();
  458. }
  459. $width = $style->width;
  460. $val = null;
  461. if (is_percent($width)) {
  462. $var = "percent";
  463. $val = (float)rtrim($width, "% ") / $colspan;
  464. } else if ($width !== "auto") {
  465. $var = "absolute";
  466. $val = $style->length_in_pt($frame_min) / $colspan;
  467. }
  468. $min = 0;
  469. $max = 0;
  470. for ($cs = 0; $cs < $colspan; $cs++) {
  471. // Resolve the frame's width(s) with other cells
  472. $col = &$this->get_column($this->__col + $cs);
  473. // Note: $var is either 'percent' or 'absolute'. We compare the
  474. // requested percentage or absolute values with the existing widths
  475. // and adjust accordingly.
  476. if (isset($var) && $val > $col[$var]) {
  477. $col[$var] = $val;
  478. $col["auto"] = false;
  479. }
  480. $min += $col["min-width"];
  481. $max += $col["max-width"];
  482. }
  483. if ($frame_min > $min) {
  484. // The frame needs more space. Expand each sub-column
  485. // FIXME try to avoid putting this dummy value when table-layout:fixed
  486. $inc = ($this->is_layout_fixed() ? 10e-10 : ($frame_min - $min) / $colspan);
  487. for ($c = 0; $c < $colspan; $c++) {
  488. $col = &$this->get_column($this->__col + $c);
  489. $col["min-width"] += $inc;
  490. }
  491. }
  492. if ($frame_max > $max) {
  493. // FIXME try to avoid putting this dummy value when table-layout:fixed
  494. $inc = ($this->is_layout_fixed() ? 10e-10 : ($frame_max - $max) / $colspan);
  495. for ($c = 0; $c < $colspan; $c++) {
  496. $col = &$this->get_column($this->__col + $c);
  497. $col["max-width"] += $inc;
  498. }
  499. }
  500. }
  501. $this->__col += $colspan;
  502. if ($this->__col > $this->_num_cols)
  503. $this->_num_cols = $this->__col;
  504. }
  505. //........................................................................
  506. function add_row()
  507. {
  508. $this->__row++;
  509. $this->_num_rows++;
  510. // Find the next available column
  511. $i = 0;
  512. while (isset($this->_cells[$this->__row][$i])) {
  513. $i++;
  514. }
  515. $this->__col = $i;
  516. }
  517. //........................................................................
  518. /**
  519. * Remove a row from the cellmap.
  520. *
  521. * @param Frame
  522. */
  523. function remove_row(Frame $row)
  524. {
  525. $key = $row->get_id();
  526. if (!isset($this->_frames[$key])) {
  527. return; // Presumably this row has alredy been removed
  528. }
  529. $this->_row = $this->_num_rows--;
  530. $rows = $this->_frames[$key]["rows"];
  531. $columns = $this->_frames[$key]["columns"];
  532. // Remove all frames from this row
  533. foreach ($rows as $r) {
  534. foreach ($columns as $c) {
  535. if (isset($this->_cells[$r][$c])) {
  536. $id = $this->_cells[$r][$c]->get_id();
  537. $this->_frames[$id] = null;
  538. unset($this->_frames[$id]);
  539. $this->_cells[$r][$c] = null;
  540. unset($this->_cells[$r][$c]);
  541. }
  542. }
  543. $this->_rows[$r] = null;
  544. unset($this->_rows[$r]);
  545. }
  546. $this->_frames[$key] = null;
  547. unset($this->_frames[$key]);
  548. }
  549. /**
  550. * Remove a row group from the cellmap.
  551. *
  552. * @param Frame $group The group to remove
  553. */
  554. function remove_row_group(Frame $group)
  555. {
  556. $key = $group->get_id();
  557. if (!isset($this->_frames[$key])) {
  558. return; // Presumably this row has alredy been removed
  559. }
  560. $iter = $group->get_first_child();
  561. while ($iter) {
  562. $this->remove_row($iter);
  563. $iter = $iter->get_next_sibling();
  564. }
  565. $this->_frames[$key] = null;
  566. unset($this->_frames[$key]);
  567. }
  568. /**
  569. * Update a row group after rows have been removed
  570. *
  571. * @param Frame $group The group to update
  572. * @param Frame $last_row The last row in the row group
  573. */
  574. function update_row_group(Frame $group, Frame $last_row)
  575. {
  576. $g_key = $group->get_id();
  577. $r_key = $last_row->get_id();
  578. //cambiado por mi
  579. $r_rows = $this->_frames[$g_key]["rows"];
  580. $this->_frames[$g_key]["rows"] = range($this->_frames[$g_key]["rows"][0], end($r_rows));
  581. }
  582. //........................................................................
  583. function assign_x_positions()
  584. {
  585. // Pre-condition: widths must be resolved and assigned to columns and
  586. // column[0]["x"] must be set.
  587. if ($this->_columns_locked) {
  588. return;
  589. }
  590. $x = $this->_columns[0]["x"];
  591. foreach (array_keys($this->_columns) as $j) {
  592. $this->_columns[$j]["x"] = $x;
  593. $x += $this->_columns[$j]["used-width"];
  594. }
  595. }
  596. function assign_frame_heights()
  597. {
  598. // Pre-condition: widths and heights of each column & row must be
  599. // calcluated
  600. foreach ($this->_frames as $arr) {
  601. $frame = $arr["frame"];
  602. $h = 0;
  603. foreach ($arr["rows"] as $row) {
  604. if (!isset($this->_rows[$row])) {
  605. // The row has been removed because of a page split, so skip it.
  606. continue;
  607. }
  608. $h += $this->_rows[$row]["height"];
  609. }
  610. if ($frame instanceof Table_Cell_Frame_Decorator) {
  611. $frame->set_cell_height($h);
  612. } else {
  613. $frame->get_style()->height = $h;
  614. }
  615. }
  616. }
  617. //........................................................................
  618. /**
  619. * Re-adjust frame height if the table height is larger than its content
  620. */
  621. function set_frame_heights($table_height, $content_height)
  622. {
  623. // Distribute the increased height proportionally amongst each row
  624. foreach ($this->_frames as $arr) {
  625. $frame = $arr["frame"];
  626. $h = 0;
  627. foreach ($arr["rows"] as $row) {
  628. if (!isset($this->_rows[$row])) {
  629. continue;
  630. }
  631. $h += $this->_rows[$row]["height"];
  632. }
  633. if ($content_height > 0) {
  634. $new_height = ($h / $content_height) * $table_height;
  635. } else {
  636. $new_height = 0;
  637. }
  638. if ($frame instanceof Table_Cell_Frame_Decorator) {
  639. $frame->set_cell_height($new_height);
  640. } else {
  641. $frame->get_style()->height = $new_height;
  642. }
  643. }
  644. }
  645. //........................................................................
  646. // Used for debugging:
  647. function __toString()
  648. {
  649. $str = "";
  650. $str .= "Columns:<br/>";
  651. $str .= pre_r($this->_columns, true);
  652. $str .= "Rows:<br/>";
  653. $str .= pre_r($this->_rows, true);
  654. $str .= "Frames:<br/>";
  655. $arr = array();
  656. foreach ($this->_frames as $key => $val) {
  657. $arr[$key] = array("columns" => $val["columns"], "rows" => $val["rows"]);
  658. }
  659. $str .= pre_r($arr, true);
  660. if (php_sapi_name() == "cli") {
  661. $str = strip_tags(str_replace(
  662. array("<br/>", "<b>", "</b>"),
  663. array("\n", chr(27) . "[01;33m", chr(27) . "[0m"),
  664. $str
  665. ));
  666. }
  667. return $str;
  668. }
  669. }