@@ -16,52 +16,52 @@ |
||
16 | 16 | */ |
17 | 17 | class Menu extends AbstractRendering { |
18 | 18 | |
19 | - /** |
|
20 | - * Render the given element |
|
21 | - * |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function renderInternal() { |
|
25 | - $str = $this->contentObject->cObjGetSingle($this->configuration['menu'], $this->configuration['menu.']); |
|
26 | - $str = $this->breakBulletList($this->contentObject, trim(strip_tags(preg_replace('/<br\s*\/?>/i', chr(10), $this->parseBody($str))))); |
|
27 | - return $str; |
|
28 | - } |
|
19 | + /** |
|
20 | + * Render the given element |
|
21 | + * |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function renderInternal() { |
|
25 | + $str = $this->contentObject->cObjGetSingle($this->configuration['menu'], $this->configuration['menu.']); |
|
26 | + $str = $this->breakBulletList($this->contentObject, trim(strip_tags(preg_replace('/<br\s*\/?>/i', chr(10), $this->parseBody($str))))); |
|
27 | + return $str; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Breaks content lines into a bullet list |
|
32 | - * |
|
33 | - * @param ContentObjectRenderer $contentObject |
|
34 | - * @param string $str Content string to make into a bullet list |
|
35 | - * |
|
36 | - * @return string Processed value |
|
37 | - */ |
|
38 | - function breakBulletList($contentObject, $str) { |
|
39 | - $type = $contentObject->data['layout']; |
|
40 | - $type = MathUtility::forceIntegerInRange($type, 0, 3); |
|
30 | + /** |
|
31 | + * Breaks content lines into a bullet list |
|
32 | + * |
|
33 | + * @param ContentObjectRenderer $contentObject |
|
34 | + * @param string $str Content string to make into a bullet list |
|
35 | + * |
|
36 | + * @return string Processed value |
|
37 | + */ |
|
38 | + function breakBulletList($contentObject, $str) { |
|
39 | + $type = $contentObject->data['layout']; |
|
40 | + $type = MathUtility::forceIntegerInRange($type, 0, 3); |
|
41 | 41 | |
42 | - $tConf = $this->configuration['bulletlist.'][$type . '.']; |
|
42 | + $tConf = $this->configuration['bulletlist.'][$type . '.']; |
|
43 | 43 | |
44 | - $cParts = explode(chr(10), $str); |
|
45 | - $lines = array(); |
|
46 | - $c = 0; |
|
44 | + $cParts = explode(chr(10), $str); |
|
45 | + $lines = array(); |
|
46 | + $c = 0; |
|
47 | 47 | |
48 | - foreach ($cParts as $substrs) { |
|
49 | - if (!strlen($substrs)) { |
|
50 | - continue; |
|
51 | - } |
|
52 | - $c++; |
|
53 | - $bullet = $tConf['bullet'] ? $tConf['bullet'] : ' - '; |
|
54 | - $bLen = strlen($bullet); |
|
55 | - $bullet = substr(str_replace('#', $c, $bullet), 0, $bLen); |
|
56 | - $secondRow = substr($tConf['secondRow'] ? $tConf['secondRow'] : str_pad('', strlen($bullet), ' '), 0, $bLen); |
|
48 | + foreach ($cParts as $substrs) { |
|
49 | + if (!strlen($substrs)) { |
|
50 | + continue; |
|
51 | + } |
|
52 | + $c++; |
|
53 | + $bullet = $tConf['bullet'] ? $tConf['bullet'] : ' - '; |
|
54 | + $bLen = strlen($bullet); |
|
55 | + $bullet = substr(str_replace('#', $c, $bullet), 0, $bLen); |
|
56 | + $secondRow = substr($tConf['secondRow'] ? $tConf['secondRow'] : str_pad('', strlen($bullet), ' '), 0, $bLen); |
|
57 | 57 | |
58 | - $lines[] = $bullet . $this->breakLines($substrs, chr(10) . $secondRow, Configuration::getPlainTextWith() - $bLen); |
|
58 | + $lines[] = $bullet . $this->breakLines($substrs, chr(10) . $secondRow, Configuration::getPlainTextWith() - $bLen); |
|
59 | 59 | |
60 | - $blanks = MathUtility::forceIntegerInRange($tConf['blanks'], 0, 1000); |
|
61 | - if ($blanks) { |
|
62 | - $lines[] = str_pad('', $blanks - 1, chr(10)); |
|
63 | - } |
|
64 | - } |
|
65 | - return implode(chr(10), $lines); |
|
66 | - } |
|
60 | + $blanks = MathUtility::forceIntegerInRange($tConf['blanks'], 0, 1000); |
|
61 | + if ($blanks) { |
|
62 | + $lines[] = str_pad('', $blanks - 1, chr(10)); |
|
63 | + } |
|
64 | + } |
|
65 | + return implode(chr(10), $lines); |
|
66 | + } |
|
67 | 67 | } |
68 | 68 | \ No newline at end of file |
@@ -16,81 +16,81 @@ |
||
16 | 16 | */ |
17 | 17 | class Image extends AbstractRendering { |
18 | 18 | |
19 | - /** |
|
20 | - * Render the given element |
|
21 | - * |
|
22 | - * @return array |
|
23 | - */ |
|
24 | - public function renderInternal() { |
|
25 | - $objectManager = new ObjectManager(); |
|
26 | - /** @var FileRepository $fileRepository */ |
|
27 | - $fileRepository = $objectManager->get('TYPO3\\CMS\\Core\\Resource\\FileRepository'); |
|
28 | - $files = $fileRepository->findByRelation('tt_content', 'image', $this->contentObject->data['uid']); |
|
19 | + /** |
|
20 | + * Render the given element |
|
21 | + * |
|
22 | + * @return array |
|
23 | + */ |
|
24 | + public function renderInternal() { |
|
25 | + $objectManager = new ObjectManager(); |
|
26 | + /** @var FileRepository $fileRepository */ |
|
27 | + $fileRepository = $objectManager->get('TYPO3\\CMS\\Core\\Resource\\FileRepository'); |
|
28 | + $files = $fileRepository->findByRelation('tt_content', 'image', $this->contentObject->data['uid']); |
|
29 | 29 | |
30 | - $images_arr = array(); |
|
31 | - foreach ($files as $file) { |
|
32 | - /** @var $file File */ |
|
33 | - $images_arr[] = $this->getLink($file->getPublicUrl()); |
|
34 | - } |
|
30 | + $images_arr = array(); |
|
31 | + foreach ($files as $file) { |
|
32 | + /** @var $file File */ |
|
33 | + $images_arr[] = $this->getLink($file->getPublicUrl()); |
|
34 | + } |
|
35 | 35 | |
36 | - $lines[] = $this->renderImagesHelper($images_arr, !$this->contentObject->data['image_zoom'] ? $this->contentObject->data['image_link'] : '', $this->contentObject->data['imagecaption']); |
|
36 | + $lines[] = $this->renderImagesHelper($images_arr, !$this->contentObject->data['image_zoom'] ? $this->contentObject->data['image_link'] : '', $this->contentObject->data['imagecaption']); |
|
37 | 37 | |
38 | - return $lines; |
|
38 | + return $lines; |
|
39 | 39 | |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Render block of images - which means creating lines with links to the images. |
|
44 | - * |
|
45 | - * @param array $images_arr : the image array |
|
46 | - * @param string $links : Link value from the "image_link" field in tt_content records |
|
47 | - * @param string $caption : Caption text |
|
48 | - * |
|
49 | - * @return string Content |
|
50 | - * @see getImages() |
|
51 | - */ |
|
52 | - function renderImagesHelper($images_arr, $links, $caption) { |
|
53 | - $linksArr = explode(',', $links); |
|
54 | - $lines = array(); |
|
55 | - $imageExists = FALSE; |
|
42 | + /** |
|
43 | + * Render block of images - which means creating lines with links to the images. |
|
44 | + * |
|
45 | + * @param array $images_arr : the image array |
|
46 | + * @param string $links : Link value from the "image_link" field in tt_content records |
|
47 | + * @param string $caption : Caption text |
|
48 | + * |
|
49 | + * @return string Content |
|
50 | + * @see getImages() |
|
51 | + */ |
|
52 | + function renderImagesHelper($images_arr, $links, $caption) { |
|
53 | + $linksArr = explode(',', $links); |
|
54 | + $lines = array(); |
|
55 | + $imageExists = FALSE; |
|
56 | 56 | |
57 | - foreach ($images_arr as $k => $file) { |
|
58 | - if (strlen(trim($file)) > 0) { |
|
59 | - $lines[] = $file; |
|
60 | - if ($links && count($linksArr) > 1) { |
|
61 | - if (isset($linksArr[$k])) { |
|
62 | - $ll = $linksArr[$k]; |
|
63 | - } else { |
|
64 | - $ll = $linksArr[0]; |
|
65 | - } |
|
57 | + foreach ($images_arr as $k => $file) { |
|
58 | + if (strlen(trim($file)) > 0) { |
|
59 | + $lines[] = $file; |
|
60 | + if ($links && count($linksArr) > 1) { |
|
61 | + if (isset($linksArr[$k])) { |
|
62 | + $ll = $linksArr[$k]; |
|
63 | + } else { |
|
64 | + $ll = $linksArr[0]; |
|
65 | + } |
|
66 | 66 | |
67 | - $theLink = $this->getLink($ll); |
|
68 | - if ($theLink) { |
|
69 | - $lines[] = $this->configuration['images.']['linkPrefix'] . $theLink; |
|
70 | - } |
|
71 | - } |
|
72 | - $imageExists = TRUE; |
|
73 | - } |
|
74 | - } |
|
75 | - if ($this->configuration['images.']['header'] && $imageExists) { |
|
76 | - array_unshift($lines, $this->configuration['images.']['header']); |
|
77 | - } |
|
78 | - if ($links && count($linksArr) == 1) { |
|
79 | - $theLink = $this->getLink($links); |
|
80 | - if ($theLink) { |
|
81 | - $lines[] = $this->configuration['images.']['linkPrefix'] . $theLink; |
|
82 | - } |
|
83 | - } |
|
84 | - if ($caption) { |
|
85 | - $lines[] = ''; |
|
86 | - $cHeader = trim($this->configuration['images.']['captionHeader']); |
|
87 | - if ($cHeader) { |
|
88 | - $lines[] = $cHeader; |
|
89 | - } |
|
90 | - $lines[] = $this->breakContent($caption); |
|
91 | - } |
|
67 | + $theLink = $this->getLink($ll); |
|
68 | + if ($theLink) { |
|
69 | + $lines[] = $this->configuration['images.']['linkPrefix'] . $theLink; |
|
70 | + } |
|
71 | + } |
|
72 | + $imageExists = TRUE; |
|
73 | + } |
|
74 | + } |
|
75 | + if ($this->configuration['images.']['header'] && $imageExists) { |
|
76 | + array_unshift($lines, $this->configuration['images.']['header']); |
|
77 | + } |
|
78 | + if ($links && count($linksArr) == 1) { |
|
79 | + $theLink = $this->getLink($links); |
|
80 | + if ($theLink) { |
|
81 | + $lines[] = $this->configuration['images.']['linkPrefix'] . $theLink; |
|
82 | + } |
|
83 | + } |
|
84 | + if ($caption) { |
|
85 | + $lines[] = ''; |
|
86 | + $cHeader = trim($this->configuration['images.']['captionHeader']); |
|
87 | + if ($cHeader) { |
|
88 | + $lines[] = $cHeader; |
|
89 | + } |
|
90 | + $lines[] = $this->breakContent($caption); |
|
91 | + } |
|
92 | 92 | |
93 | - return chr(10) . implode(chr(10), $lines); |
|
94 | - } |
|
93 | + return chr(10) . implode(chr(10), $lines); |
|
94 | + } |
|
95 | 95 | |
96 | 96 | } |
97 | 97 | \ No newline at end of file |
@@ -15,346 +15,346 @@ |
||
15 | 15 | */ |
16 | 16 | class Table extends AbstractRendering { |
17 | 17 | |
18 | - /** |
|
19 | - * Table settings |
|
20 | - * |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $tableSettings = array( |
|
24 | - 'default' => array( |
|
25 | - 'join' => '+', |
|
26 | - 'xChar' => '-', |
|
27 | - 'xCharHeader' => '-', |
|
28 | - 'yChar' => '|', |
|
29 | - 'yCharHeader' => '|', |
|
30 | - 'xSpace' => 1, |
|
31 | - 'ySpace' => 0, |
|
32 | - 'separateData' => FALSE, |
|
33 | - 'separateHeader' => TRUE, |
|
34 | - 'outerTop' => TRUE, |
|
35 | - 'outerBottom' => TRUE, |
|
36 | - 'outerLeft' => TRUE, |
|
37 | - 'outerRight' => TRUE, |
|
38 | - ), |
|
39 | - 'ascii_old' => array( |
|
40 | - 'join' => '+', |
|
41 | - 'xChar' => '-', |
|
42 | - 'xCharHeader' => '=', |
|
43 | - 'yChar' => '|', |
|
44 | - 'yCharHeader' => '|', |
|
45 | - 'xSpace' => 1, |
|
46 | - 'ySpace' => 0, |
|
47 | - 'separateData' => TRUE, |
|
48 | - 'separateHeader' => TRUE, |
|
49 | - 'outerTop' => TRUE, |
|
50 | - 'outerBottom' => TRUE, |
|
51 | - 'outerLeft' => TRUE, |
|
52 | - 'outerRight' => TRUE, |
|
53 | - ), |
|
54 | - 'ascii_compact' => array( |
|
55 | - 'join' => ' ', |
|
56 | - 'xChar' => ' ', |
|
57 | - 'xCharHeader' => '=', |
|
58 | - 'yChar' => ' ', |
|
59 | - 'yCharHeader' => ' ', |
|
60 | - 'xSpace' => 0, |
|
61 | - 'ySpace' => 0, |
|
62 | - 'separateData' => FALSE, |
|
63 | - 'separateHeader' => TRUE, |
|
64 | - 'outerTop' => FALSE, |
|
65 | - 'outerBottom' => FALSE, |
|
66 | - 'outerLeft' => FALSE, |
|
67 | - 'outerRight' => FALSE, |
|
68 | - ), |
|
69 | - 'unicode' => array( |
|
70 | - 'join' => '╬', |
|
71 | - 'xChar' => '═', |
|
72 | - 'xCharHeader' => '═', |
|
73 | - 'yChar' => '║', |
|
74 | - 'yCharHeader' => '║', |
|
75 | - 'xSpace' => 1, |
|
76 | - 'ySpace' => 0, |
|
77 | - 'separateData' => FALSE, |
|
78 | - 'separateHeader' => TRUE, |
|
79 | - 'outerTop' => TRUE, |
|
80 | - 'outerBottom' => TRUE, |
|
81 | - 'outerLeft' => TRUE, |
|
82 | - 'outerRight' => TRUE, |
|
83 | - ), |
|
84 | - 'markdown' => array( |
|
85 | - 'join' => ' ', |
|
86 | - 'xChar' => ' ', |
|
87 | - 'xCharHeader' => '-', |
|
88 | - 'yChar' => '|', |
|
89 | - 'yCharHeader' => '|', |
|
90 | - 'xSpace' => 1, |
|
91 | - 'ySpace' => 0, |
|
92 | - 'separateData' => FALSE, |
|
93 | - 'separateHeader' => TRUE, |
|
94 | - 'outerTop' => FALSE, |
|
95 | - 'outerBottom' => FALSE, |
|
96 | - 'outerLeft' => TRUE, |
|
97 | - 'outerRight' => TRUE, |
|
98 | - ), |
|
99 | - ); |
|
18 | + /** |
|
19 | + * Table settings |
|
20 | + * |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $tableSettings = array( |
|
24 | + 'default' => array( |
|
25 | + 'join' => '+', |
|
26 | + 'xChar' => '-', |
|
27 | + 'xCharHeader' => '-', |
|
28 | + 'yChar' => '|', |
|
29 | + 'yCharHeader' => '|', |
|
30 | + 'xSpace' => 1, |
|
31 | + 'ySpace' => 0, |
|
32 | + 'separateData' => FALSE, |
|
33 | + 'separateHeader' => TRUE, |
|
34 | + 'outerTop' => TRUE, |
|
35 | + 'outerBottom' => TRUE, |
|
36 | + 'outerLeft' => TRUE, |
|
37 | + 'outerRight' => TRUE, |
|
38 | + ), |
|
39 | + 'ascii_old' => array( |
|
40 | + 'join' => '+', |
|
41 | + 'xChar' => '-', |
|
42 | + 'xCharHeader' => '=', |
|
43 | + 'yChar' => '|', |
|
44 | + 'yCharHeader' => '|', |
|
45 | + 'xSpace' => 1, |
|
46 | + 'ySpace' => 0, |
|
47 | + 'separateData' => TRUE, |
|
48 | + 'separateHeader' => TRUE, |
|
49 | + 'outerTop' => TRUE, |
|
50 | + 'outerBottom' => TRUE, |
|
51 | + 'outerLeft' => TRUE, |
|
52 | + 'outerRight' => TRUE, |
|
53 | + ), |
|
54 | + 'ascii_compact' => array( |
|
55 | + 'join' => ' ', |
|
56 | + 'xChar' => ' ', |
|
57 | + 'xCharHeader' => '=', |
|
58 | + 'yChar' => ' ', |
|
59 | + 'yCharHeader' => ' ', |
|
60 | + 'xSpace' => 0, |
|
61 | + 'ySpace' => 0, |
|
62 | + 'separateData' => FALSE, |
|
63 | + 'separateHeader' => TRUE, |
|
64 | + 'outerTop' => FALSE, |
|
65 | + 'outerBottom' => FALSE, |
|
66 | + 'outerLeft' => FALSE, |
|
67 | + 'outerRight' => FALSE, |
|
68 | + ), |
|
69 | + 'unicode' => array( |
|
70 | + 'join' => '╬', |
|
71 | + 'xChar' => '═', |
|
72 | + 'xCharHeader' => '═', |
|
73 | + 'yChar' => '║', |
|
74 | + 'yCharHeader' => '║', |
|
75 | + 'xSpace' => 1, |
|
76 | + 'ySpace' => 0, |
|
77 | + 'separateData' => FALSE, |
|
78 | + 'separateHeader' => TRUE, |
|
79 | + 'outerTop' => TRUE, |
|
80 | + 'outerBottom' => TRUE, |
|
81 | + 'outerLeft' => TRUE, |
|
82 | + 'outerRight' => TRUE, |
|
83 | + ), |
|
84 | + 'markdown' => array( |
|
85 | + 'join' => ' ', |
|
86 | + 'xChar' => ' ', |
|
87 | + 'xCharHeader' => '-', |
|
88 | + 'yChar' => '|', |
|
89 | + 'yCharHeader' => '|', |
|
90 | + 'xSpace' => 1, |
|
91 | + 'ySpace' => 0, |
|
92 | + 'separateData' => FALSE, |
|
93 | + 'separateHeader' => TRUE, |
|
94 | + 'outerTop' => FALSE, |
|
95 | + 'outerBottom' => FALSE, |
|
96 | + 'outerLeft' => TRUE, |
|
97 | + 'outerRight' => TRUE, |
|
98 | + ), |
|
99 | + ); |
|
100 | 100 | |
101 | - /** |
|
102 | - * Render mode |
|
103 | - * |
|
104 | - * @var string |
|
105 | - */ |
|
106 | - protected $renderMode = 'markdown'; |
|
101 | + /** |
|
102 | + * Render mode |
|
103 | + * |
|
104 | + * @var string |
|
105 | + */ |
|
106 | + protected $renderMode = 'markdown'; |
|
107 | 107 | |
108 | - /** |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - public function renderInternal() { |
|
112 | - $controller = GeneralUtility::makeInstance('TYPO3\\CMS\\CssStyledContent\\Controller\\CssStyledContentController'); |
|
113 | - $controller->cObj = $this->contentObject; |
|
114 | - $this->renderMode = Configuration::getTableMode(); |
|
115 | - $htmlTable = $controller->render_table(); |
|
116 | - $tableData = $this->parseHtmlTable($htmlTable); |
|
117 | - return $this->getTable($tableData); |
|
118 | - } |
|
108 | + /** |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + public function renderInternal() { |
|
112 | + $controller = GeneralUtility::makeInstance('TYPO3\\CMS\\CssStyledContent\\Controller\\CssStyledContentController'); |
|
113 | + $controller->cObj = $this->contentObject; |
|
114 | + $this->renderMode = Configuration::getTableMode(); |
|
115 | + $htmlTable = $controller->render_table(); |
|
116 | + $tableData = $this->parseHtmlTable($htmlTable); |
|
117 | + return $this->getTable($tableData); |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * @param $html |
|
122 | - * |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - protected function parseHtmlTable($html) { |
|
126 | - $dom = new \DOMDocument(); |
|
120 | + /** |
|
121 | + * @param $html |
|
122 | + * |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + protected function parseHtmlTable($html) { |
|
126 | + $dom = new \DOMDocument(); |
|
127 | 127 | |
128 | - //load the html |
|
129 | - $html = $dom->loadHTML(utf8_decode($html)); |
|
128 | + //load the html |
|
129 | + $html = $dom->loadHTML(utf8_decode($html)); |
|
130 | 130 | |
131 | - //discard white space |
|
132 | - $dom->preserveWhiteSpace = FALSE; |
|
131 | + //discard white space |
|
132 | + $dom->preserveWhiteSpace = FALSE; |
|
133 | 133 | |
134 | - //the table by its tag name |
|
135 | - $tables = $dom->getElementsByTagName('table'); |
|
134 | + //the table by its tag name |
|
135 | + $tables = $dom->getElementsByTagName('table'); |
|
136 | 136 | |
137 | - //get all rows from the table |
|
138 | - $rows = $tables->item(0) |
|
139 | - ->getElementsByTagName('tr'); |
|
140 | - // get each column by tag name |
|
141 | - $cols = $rows->item(0) |
|
142 | - ->getElementsByTagName('th'); |
|
143 | - $row_headers = NULL; |
|
144 | - foreach ($cols as $node) { |
|
145 | - //print $node->nodeValue."\n"; |
|
146 | - $row_headers[] = $node->nodeValue; |
|
147 | - } |
|
137 | + //get all rows from the table |
|
138 | + $rows = $tables->item(0) |
|
139 | + ->getElementsByTagName('tr'); |
|
140 | + // get each column by tag name |
|
141 | + $cols = $rows->item(0) |
|
142 | + ->getElementsByTagName('th'); |
|
143 | + $row_headers = NULL; |
|
144 | + foreach ($cols as $node) { |
|
145 | + //print $node->nodeValue."\n"; |
|
146 | + $row_headers[] = $node->nodeValue; |
|
147 | + } |
|
148 | 148 | |
149 | - $table = array(); |
|
150 | - //get all rows from the table |
|
151 | - $rows = $tables->item(0) |
|
152 | - ->getElementsByTagName('tr'); |
|
153 | - foreach ($rows as $row) { |
|
154 | - // get each column by tag name |
|
155 | - $cols = $row->getElementsByTagName('td'); |
|
156 | - $row = array(); |
|
157 | - $i = 0; |
|
158 | - foreach ($cols as $node) { |
|
159 | - # code... |
|
160 | - //print $node->nodeValue."\n"; |
|
161 | - if ($row_headers == NULL) { |
|
162 | - $row[] = $node->nodeValue; |
|
163 | - } else { |
|
164 | - $row[$row_headers[$i]] = $node->nodeValue; |
|
165 | - } |
|
166 | - $i++; |
|
167 | - } |
|
168 | - $table[] = $row; |
|
169 | - } |
|
149 | + $table = array(); |
|
150 | + //get all rows from the table |
|
151 | + $rows = $tables->item(0) |
|
152 | + ->getElementsByTagName('tr'); |
|
153 | + foreach ($rows as $row) { |
|
154 | + // get each column by tag name |
|
155 | + $cols = $row->getElementsByTagName('td'); |
|
156 | + $row = array(); |
|
157 | + $i = 0; |
|
158 | + foreach ($cols as $node) { |
|
159 | + # code... |
|
160 | + //print $node->nodeValue."\n"; |
|
161 | + if ($row_headers == NULL) { |
|
162 | + $row[] = $node->nodeValue; |
|
163 | + } else { |
|
164 | + $row[$row_headers[$i]] = $node->nodeValue; |
|
165 | + } |
|
166 | + $i++; |
|
167 | + } |
|
168 | + $table[] = $row; |
|
169 | + } |
|
170 | 170 | |
171 | - return $table; |
|
172 | - } |
|
171 | + return $table; |
|
172 | + } |
|
173 | 173 | |
174 | - /** |
|
175 | - * Get the table |
|
176 | - * |
|
177 | - * @param $table |
|
178 | - * |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - function getTable($table) { |
|
182 | - $lines = array(); |
|
183 | - $columnsHeaders = $this->columns_headers($table); |
|
184 | - $columns_lengths = $this->columns_lengths($table, $columnsHeaders); |
|
174 | + /** |
|
175 | + * Get the table |
|
176 | + * |
|
177 | + * @param $table |
|
178 | + * |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + function getTable($table) { |
|
182 | + $lines = array(); |
|
183 | + $columnsHeaders = $this->columns_headers($table); |
|
184 | + $columns_lengths = $this->columns_lengths($table, $columnsHeaders); |
|
185 | 185 | |
186 | - $topLine = $this->renderLine($columns_lengths, 'top', 'CharHeader'); |
|
187 | - if ($topLine) { |
|
188 | - $lines[] = $topLine; |
|
189 | - } |
|
190 | - $lines[] = $this->renderHeader($columns_lengths, $columnsHeaders); |
|
191 | - if ($this->tableSettings[$this->renderMode]['separateHeader']) { |
|
192 | - $lines[] = $this->renderLine($columns_lengths, 'default', 'CharHeader'); |
|
193 | - } |
|
194 | - foreach ($table as $row_cells) { |
|
195 | - $lines[] = $this->renderCell($row_cells, $columnsHeaders, $columns_lengths); |
|
196 | - if ($this->tableSettings[$this->renderMode]['separateData']) { |
|
197 | - $lines[] = $this->renderLine($columns_lengths); |
|
198 | - } |
|
199 | - } |
|
186 | + $topLine = $this->renderLine($columns_lengths, 'top', 'CharHeader'); |
|
187 | + if ($topLine) { |
|
188 | + $lines[] = $topLine; |
|
189 | + } |
|
190 | + $lines[] = $this->renderHeader($columns_lengths, $columnsHeaders); |
|
191 | + if ($this->tableSettings[$this->renderMode]['separateHeader']) { |
|
192 | + $lines[] = $this->renderLine($columns_lengths, 'default', 'CharHeader'); |
|
193 | + } |
|
194 | + foreach ($table as $row_cells) { |
|
195 | + $lines[] = $this->renderCell($row_cells, $columnsHeaders, $columns_lengths); |
|
196 | + if ($this->tableSettings[$this->renderMode]['separateData']) { |
|
197 | + $lines[] = $this->renderLine($columns_lengths); |
|
198 | + } |
|
199 | + } |
|
200 | 200 | |
201 | - $bottomLine = $this->renderLine($columns_lengths, 'bottom'); |
|
202 | - if ($bottomLine) { |
|
203 | - $lines[] = $bottomLine; |
|
204 | - } |
|
205 | - return $lines; |
|
206 | - } |
|
201 | + $bottomLine = $this->renderLine($columns_lengths, 'bottom'); |
|
202 | + if ($bottomLine) { |
|
203 | + $lines[] = $bottomLine; |
|
204 | + } |
|
205 | + return $lines; |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * Render a separation line |
|
210 | - * |
|
211 | - * @param $columnsLengths |
|
212 | - * @param string $specialLine |
|
213 | - * @param string $charMode |
|
214 | - * |
|
215 | - * @return string |
|
216 | - */ |
|
217 | - protected function renderLine($columnsLengths, $specialLine = 'default', $charMode = 'Char') { |
|
218 | - if (isset($this->tableSettings[$this->renderMode]['outer' . ucfirst($specialLine)]) && $this->tableSettings[$this->renderMode]['outer' . ucfirst($specialLine)] === FALSE) { |
|
219 | - return FALSE; |
|
220 | - } |
|
221 | - $row = ''; |
|
222 | - foreach ($columnsLengths as $key => $column_length) { |
|
223 | - if ($key !== 0 || $this->tableSettings[$this->renderMode]['outerLeft']) { |
|
224 | - $row .= $this->tableSettings[$this->renderMode]['join']; |
|
225 | - } |
|
226 | - $row .= str_repeat($this->tableSettings[$this->renderMode]['x' . $charMode], ($this->tableSettings[$this->renderMode]['xSpace'] * 2) + $column_length); |
|
227 | - } |
|
228 | - if ($this->tableSettings[$this->renderMode]['outerRight']) { |
|
229 | - $row .= $this->tableSettings[$this->renderMode]['join']; |
|
230 | - } |
|
231 | - return $row; |
|
232 | - } |
|
208 | + /** |
|
209 | + * Render a separation line |
|
210 | + * |
|
211 | + * @param $columnsLengths |
|
212 | + * @param string $specialLine |
|
213 | + * @param string $charMode |
|
214 | + * |
|
215 | + * @return string |
|
216 | + */ |
|
217 | + protected function renderLine($columnsLengths, $specialLine = 'default', $charMode = 'Char') { |
|
218 | + if (isset($this->tableSettings[$this->renderMode]['outer' . ucfirst($specialLine)]) && $this->tableSettings[$this->renderMode]['outer' . ucfirst($specialLine)] === FALSE) { |
|
219 | + return FALSE; |
|
220 | + } |
|
221 | + $row = ''; |
|
222 | + foreach ($columnsLengths as $key => $column_length) { |
|
223 | + if ($key !== 0 || $this->tableSettings[$this->renderMode]['outerLeft']) { |
|
224 | + $row .= $this->tableSettings[$this->renderMode]['join']; |
|
225 | + } |
|
226 | + $row .= str_repeat($this->tableSettings[$this->renderMode]['x' . $charMode], ($this->tableSettings[$this->renderMode]['xSpace'] * 2) + $column_length); |
|
227 | + } |
|
228 | + if ($this->tableSettings[$this->renderMode]['outerRight']) { |
|
229 | + $row .= $this->tableSettings[$this->renderMode]['join']; |
|
230 | + } |
|
231 | + return $row; |
|
232 | + } |
|
233 | 233 | |
234 | - /** |
|
235 | - * @param $columnsLengths |
|
236 | - * @param $columnsHeaders |
|
237 | - * |
|
238 | - * @return string |
|
239 | - */ |
|
240 | - protected function renderHeader($columnsLengths, $columnsHeaders) { |
|
241 | - $row = ''; |
|
242 | - foreach ($columnsHeaders as $key => $header) { |
|
243 | - if ($key !== 0 || $this->tableSettings[$this->renderMode]['outerLeft']) { |
|
244 | - $row .= $this->tableSettings[$this->renderMode]['yChar']; |
|
245 | - } |
|
246 | - $row .= str_pad($header, ($this->tableSettings[$this->renderMode]['xSpace'] * 2) + $columnsLengths[$header], ' ', STR_PAD_BOTH); |
|
247 | - } |
|
248 | - if ($this->tableSettings[$this->renderMode]['outerRight']) { |
|
249 | - $row .= $this->tableSettings[$this->renderMode]['yChar']; |
|
250 | - } |
|
251 | - return $row; |
|
252 | - } |
|
234 | + /** |
|
235 | + * @param $columnsLengths |
|
236 | + * @param $columnsHeaders |
|
237 | + * |
|
238 | + * @return string |
|
239 | + */ |
|
240 | + protected function renderHeader($columnsLengths, $columnsHeaders) { |
|
241 | + $row = ''; |
|
242 | + foreach ($columnsHeaders as $key => $header) { |
|
243 | + if ($key !== 0 || $this->tableSettings[$this->renderMode]['outerLeft']) { |
|
244 | + $row .= $this->tableSettings[$this->renderMode]['yChar']; |
|
245 | + } |
|
246 | + $row .= str_pad($header, ($this->tableSettings[$this->renderMode]['xSpace'] * 2) + $columnsLengths[$header], ' ', STR_PAD_BOTH); |
|
247 | + } |
|
248 | + if ($this->tableSettings[$this->renderMode]['outerRight']) { |
|
249 | + $row .= $this->tableSettings[$this->renderMode]['yChar']; |
|
250 | + } |
|
251 | + return $row; |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
255 | - * @param $row_cells |
|
256 | - * @param $columns_headers |
|
257 | - * @param $columns_lengths |
|
258 | - * |
|
259 | - * @return string |
|
260 | - */ |
|
261 | - function renderCell($row_cells, $columns_headers, $columns_lengths) { |
|
262 | - $row = ''; |
|
263 | - foreach ($columns_headers as $key => $header) { |
|
264 | - $line = array(); |
|
265 | - $stringLength = mb_strlen(utf8_decode($row_cells[$header])); |
|
266 | - if ($key !== 0 || $this->tableSettings[$this->renderMode]['outerLeft']) { |
|
267 | - $line[] = $this->tableSettings[$this->renderMode]['yChar']; |
|
268 | - } |
|
269 | - $line[] = str_repeat(' ', $this->tableSettings[$this->renderMode]['xSpace']); |
|
270 | - $line[] = $row_cells[$header]; |
|
271 | - $line[] = str_repeat(' ', $columns_lengths[$header] - $stringLength + $this->tableSettings[$this->renderMode]['xSpace']); |
|
254 | + /** |
|
255 | + * @param $row_cells |
|
256 | + * @param $columns_headers |
|
257 | + * @param $columns_lengths |
|
258 | + * |
|
259 | + * @return string |
|
260 | + */ |
|
261 | + function renderCell($row_cells, $columns_headers, $columns_lengths) { |
|
262 | + $row = ''; |
|
263 | + foreach ($columns_headers as $key => $header) { |
|
264 | + $line = array(); |
|
265 | + $stringLength = mb_strlen(utf8_decode($row_cells[$header])); |
|
266 | + if ($key !== 0 || $this->tableSettings[$this->renderMode]['outerLeft']) { |
|
267 | + $line[] = $this->tableSettings[$this->renderMode]['yChar']; |
|
268 | + } |
|
269 | + $line[] = str_repeat(' ', $this->tableSettings[$this->renderMode]['xSpace']); |
|
270 | + $line[] = $row_cells[$header]; |
|
271 | + $line[] = str_repeat(' ', $columns_lengths[$header] - $stringLength + $this->tableSettings[$this->renderMode]['xSpace']); |
|
272 | 272 | |
273 | - $row .= implode('', $line); |
|
274 | - } |
|
275 | - if ($this->tableSettings[$this->renderMode]['outerRight']) { |
|
276 | - $row .= $this->tableSettings[$this->renderMode]['yChar']; |
|
277 | - } |
|
278 | - return $row; |
|
279 | - } |
|
273 | + $row .= implode('', $line); |
|
274 | + } |
|
275 | + if ($this->tableSettings[$this->renderMode]['outerRight']) { |
|
276 | + $row .= $this->tableSettings[$this->renderMode]['yChar']; |
|
277 | + } |
|
278 | + return $row; |
|
279 | + } |
|
280 | 280 | |
281 | - /** |
|
282 | - * @param $table |
|
283 | - * |
|
284 | - * @return array |
|
285 | - */ |
|
286 | - function columns_headers($table) { |
|
287 | - return array_keys(reset($table)); |
|
288 | - } |
|
281 | + /** |
|
282 | + * @param $table |
|
283 | + * |
|
284 | + * @return array |
|
285 | + */ |
|
286 | + function columns_headers($table) { |
|
287 | + return array_keys(reset($table)); |
|
288 | + } |
|
289 | 289 | |
290 | - /** |
|
291 | - * @param $table |
|
292 | - * @param $columns_headers |
|
293 | - * |
|
294 | - * @return array |
|
295 | - */ |
|
296 | - function columns_lengths($table, $columns_headers) { |
|
297 | - $lengths = array(); |
|
298 | - foreach ($columns_headers as $header) { |
|
299 | - $header_length = mb_strlen($header); |
|
300 | - $max = $header_length; |
|
301 | - foreach ($table as $row) { |
|
302 | - $length = mb_strlen($row[$header]); |
|
303 | - if ($length > $max) { |
|
304 | - $max = $length; |
|
305 | - } |
|
306 | - } |
|
290 | + /** |
|
291 | + * @param $table |
|
292 | + * @param $columns_headers |
|
293 | + * |
|
294 | + * @return array |
|
295 | + */ |
|
296 | + function columns_lengths($table, $columns_headers) { |
|
297 | + $lengths = array(); |
|
298 | + foreach ($columns_headers as $header) { |
|
299 | + $header_length = mb_strlen($header); |
|
300 | + $max = $header_length; |
|
301 | + foreach ($table as $row) { |
|
302 | + $length = mb_strlen($row[$header]); |
|
303 | + if ($length > $max) { |
|
304 | + $max = $length; |
|
305 | + } |
|
306 | + } |
|
307 | 307 | |
308 | - if (($max % 2) != ($header_length % 2)) { |
|
309 | - $max += 1; |
|
310 | - } |
|
308 | + if (($max % 2) != ($header_length % 2)) { |
|
309 | + $max += 1; |
|
310 | + } |
|
311 | 311 | |
312 | - $lengths[$header] = $max; |
|
313 | - } |
|
312 | + $lengths[$header] = $max; |
|
313 | + } |
|
314 | 314 | |
315 | - return $this->increaseLengthToo100Percent($lengths); |
|
316 | - } |
|
315 | + return $this->increaseLengthToo100Percent($lengths); |
|
316 | + } |
|
317 | 317 | |
318 | - /** |
|
319 | - * @param $lengths |
|
320 | - * |
|
321 | - * @return mixed |
|
322 | - */ |
|
323 | - protected function increaseLengthToo100Percent($lengths) { |
|
324 | - if (!Configuration::isPlainTable100()) { |
|
325 | - return $lengths; |
|
326 | - } |
|
327 | - $fullWidth = Configuration::getPlainTextWith(); |
|
318 | + /** |
|
319 | + * @param $lengths |
|
320 | + * |
|
321 | + * @return mixed |
|
322 | + */ |
|
323 | + protected function increaseLengthToo100Percent($lengths) { |
|
324 | + if (!Configuration::isPlainTable100()) { |
|
325 | + return $lengths; |
|
326 | + } |
|
327 | + $fullWidth = Configuration::getPlainTextWith(); |
|
328 | 328 | |
329 | - // Calc |
|
330 | - $rowCount = sizeof($lengths) + 1; |
|
331 | - $yCount = $rowCount - 2; |
|
332 | - $currentWidth = array_sum($lengths); |
|
333 | - if ($this->tableSettings[$this->renderMode]['outerLeft']) { |
|
334 | - $yCount++; |
|
335 | - } |
|
336 | - if ($this->tableSettings[$this->renderMode]['outerRight']) { |
|
337 | - $yCount++; |
|
338 | - } |
|
339 | - $currentWidth += strlen($this->tableSettings[$this->renderMode]['yChar']) * $yCount; |
|
340 | - $currentWidth += $this->tableSettings[$this->renderMode]['xSpace'] * $rowCount; |
|
329 | + // Calc |
|
330 | + $rowCount = sizeof($lengths) + 1; |
|
331 | + $yCount = $rowCount - 2; |
|
332 | + $currentWidth = array_sum($lengths); |
|
333 | + if ($this->tableSettings[$this->renderMode]['outerLeft']) { |
|
334 | + $yCount++; |
|
335 | + } |
|
336 | + if ($this->tableSettings[$this->renderMode]['outerRight']) { |
|
337 | + $yCount++; |
|
338 | + } |
|
339 | + $currentWidth += strlen($this->tableSettings[$this->renderMode]['yChar']) * $yCount; |
|
340 | + $currentWidth += $this->tableSettings[$this->renderMode]['xSpace'] * $rowCount; |
|
341 | 341 | |
342 | - if ($fullWidth < $currentWidth) { |
|
343 | - return $lengths; |
|
344 | - } |
|
342 | + if ($fullWidth < $currentWidth) { |
|
343 | + return $lengths; |
|
344 | + } |
|
345 | 345 | |
346 | - $moreChars = $fullWidth - $currentWidth; |
|
347 | - while ($moreChars > 0) { |
|
348 | - foreach ($lengths as $key => $value) { |
|
349 | - if ($moreChars <= 0) { |
|
350 | - break; |
|
351 | - } |
|
352 | - $lengths[$key]++; |
|
353 | - $moreChars--; |
|
346 | + $moreChars = $fullWidth - $currentWidth; |
|
347 | + while ($moreChars > 0) { |
|
348 | + foreach ($lengths as $key => $value) { |
|
349 | + if ($moreChars <= 0) { |
|
350 | + break; |
|
351 | + } |
|
352 | + $lengths[$key]++; |
|
353 | + $moreChars--; |
|
354 | 354 | |
355 | - } |
|
356 | - } |
|
355 | + } |
|
356 | + } |
|
357 | 357 | |
358 | - return $lengths; |
|
359 | - } |
|
358 | + return $lengths; |
|
359 | + } |
|
360 | 360 | } |
361 | 361 | \ No newline at end of file |