@@ -15,24 +15,24 @@ |
||
15 | 15 | */ |
16 | 16 | class Templavoila extends AbstractRendering { |
17 | 17 | |
18 | - /** |
|
19 | - * Render the given element |
|
20 | - * |
|
21 | - * @return array |
|
22 | - */ |
|
23 | - public function renderInternal() { |
|
18 | + /** |
|
19 | + * Render the given element |
|
20 | + * |
|
21 | + * @return array |
|
22 | + */ |
|
23 | + public function renderInternal() { |
|
24 | 24 | |
25 | - // TV nicht geladen |
|
26 | - if (!ExtensionManagementUtility::isLoaded('templavoila')) { |
|
27 | - $defaultOutput = $this->configuration['defaultOutput']; |
|
28 | - if ($defaultOutput) { |
|
29 | - $defaultOutput = str_replace('###CType###', $this->contentObject->data['CType'], $defaultOutput); |
|
30 | - } |
|
31 | - return $defaultOutput; |
|
32 | - } |
|
33 | - $pi1 = GeneralUtility::makeInstance('tx_templavoila_pi1'); |
|
34 | - $pi1->cObj = $this->contentObject; |
|
35 | - $lines[] = $pi1->renderElement($this->contentObject->data, 'tt_content'); |
|
36 | - return $lines; |
|
37 | - } |
|
25 | + // TV nicht geladen |
|
26 | + if (!ExtensionManagementUtility::isLoaded('templavoila')) { |
|
27 | + $defaultOutput = $this->configuration['defaultOutput']; |
|
28 | + if ($defaultOutput) { |
|
29 | + $defaultOutput = str_replace('###CType###', $this->contentObject->data['CType'], $defaultOutput); |
|
30 | + } |
|
31 | + return $defaultOutput; |
|
32 | + } |
|
33 | + $pi1 = GeneralUtility::makeInstance('tx_templavoila_pi1'); |
|
34 | + $pi1->cObj = $this->contentObject; |
|
35 | + $lines[] = $pi1->renderElement($this->contentObject->data, 'tt_content'); |
|
36 | + return $lines; |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | \ No newline at end of file |
@@ -12,12 +12,12 @@ |
||
12 | 12 | */ |
13 | 13 | class Html extends AbstractRendering { |
14 | 14 | |
15 | - /** |
|
16 | - * Get the liens for the current HTML element |
|
17 | - * |
|
18 | - * @return array |
|
19 | - */ |
|
20 | - public function renderInternal() { |
|
21 | - return array($this->breakContent(strip_tags($this->contentObject->data['bodytext']))); |
|
22 | - } |
|
15 | + /** |
|
16 | + * Get the liens for the current HTML element |
|
17 | + * |
|
18 | + * @return array |
|
19 | + */ |
|
20 | + public function renderInternal() { |
|
21 | + return array($this->breakContent(strip_tags($this->contentObject->data['bodytext']))); |
|
22 | + } |
|
23 | 23 | } |
24 | 24 | \ No newline at end of file |
@@ -12,22 +12,22 @@ |
||
12 | 12 | */ |
13 | 13 | class TextPicture extends AbstractRendering { |
14 | 14 | |
15 | - /** |
|
16 | - * Render the given element |
|
17 | - * |
|
18 | - * @return array |
|
19 | - */ |
|
20 | - public function renderInternal() { |
|
21 | - $image = new Image(); |
|
22 | - if (!($this->contentObject->data['imageorient'] & 24)) { |
|
23 | - $lines = $image->render($this->contentObject, $this->configuration); |
|
24 | - $lines[] = ''; |
|
25 | - } |
|
26 | - $lines[] = $this->breakContent(strip_tags($this->parseBody($this->contentObject->data['bodytext']))); |
|
27 | - if ($this->contentObject->data['imageorient'] & 24) { |
|
28 | - $lines[] = ''; |
|
29 | - $lines = array_merge($lines, $image->render($this->contentObject, $this->configuration)); |
|
30 | - } |
|
31 | - return $lines; |
|
32 | - } |
|
15 | + /** |
|
16 | + * Render the given element |
|
17 | + * |
|
18 | + * @return array |
|
19 | + */ |
|
20 | + public function renderInternal() { |
|
21 | + $image = new Image(); |
|
22 | + if (!($this->contentObject->data['imageorient'] & 24)) { |
|
23 | + $lines = $image->render($this->contentObject, $this->configuration); |
|
24 | + $lines[] = ''; |
|
25 | + } |
|
26 | + $lines[] = $this->breakContent(strip_tags($this->parseBody($this->contentObject->data['bodytext']))); |
|
27 | + if ($this->contentObject->data['imageorient'] & 24) { |
|
28 | + $lines[] = ''; |
|
29 | + $lines = array_merge($lines, $image->render($this->contentObject, $this->configuration)); |
|
30 | + } |
|
31 | + return $lines; |
|
32 | + } |
|
33 | 33 | } |
34 | 34 | \ No newline at end of file |
@@ -12,48 +12,48 @@ |
||
12 | 12 | */ |
13 | 13 | class Plugin extends AbstractRendering { |
14 | 14 | |
15 | - /** |
|
16 | - * Render the given element |
|
17 | - * |
|
18 | - * @return array |
|
19 | - */ |
|
20 | - public function renderInternal() { |
|
21 | - $lines = array(); |
|
22 | - $lines[] = 'Test'; |
|
23 | - $myName = FALSE; |
|
24 | - $listType = $this->contentObject->data['list_type']; |
|
25 | - $template = $GLOBALS['TSFE']->tmpl; |
|
15 | + /** |
|
16 | + * Render the given element |
|
17 | + * |
|
18 | + * @return array |
|
19 | + */ |
|
20 | + public function renderInternal() { |
|
21 | + $lines = array(); |
|
22 | + $lines[] = 'Test'; |
|
23 | + $myName = FALSE; |
|
24 | + $listType = $this->contentObject->data['list_type']; |
|
25 | + $template = $GLOBALS['TSFE']->tmpl; |
|
26 | 26 | |
27 | - if (isset($template->setup['tt_content.']['list.']['20.'][$listType])) { |
|
28 | - $theValue = $template->setup['tt_content.']['list.']['20.'][$listType]; |
|
29 | - $theConf = $template->setup['tt_content.']['list.']['20.'][$listType . '.']; |
|
30 | - } else { |
|
31 | - $tmp = explode('_pi', $listType); |
|
32 | - if (count($tmp) < 2) { |
|
33 | - $myName = 'tx_' . str_replace('_', '', $tmp[0]); |
|
34 | - } else { |
|
35 | - $myName = 'tx_' . str_replace('_', '', $tmp[0]) . '_pi' . $tmp[1]; |
|
36 | - } |
|
37 | - $theValue = $template->setup['plugin.'][$myName]; |
|
38 | - $theConf = $template->setup['plugin.'][$myName . '.']; |
|
39 | - } |
|
40 | - $content = $this->contentObject->cObjGetSingle($theValue, $theConf); |
|
27 | + if (isset($template->setup['tt_content.']['list.']['20.'][$listType])) { |
|
28 | + $theValue = $template->setup['tt_content.']['list.']['20.'][$listType]; |
|
29 | + $theConf = $template->setup['tt_content.']['list.']['20.'][$listType . '.']; |
|
30 | + } else { |
|
31 | + $tmp = explode('_pi', $listType); |
|
32 | + if (count($tmp) < 2) { |
|
33 | + $myName = 'tx_' . str_replace('_', '', $tmp[0]); |
|
34 | + } else { |
|
35 | + $myName = 'tx_' . str_replace('_', '', $tmp[0]) . '_pi' . $tmp[1]; |
|
36 | + } |
|
37 | + $theValue = $template->setup['plugin.'][$myName]; |
|
38 | + $theConf = $template->setup['plugin.'][$myName . '.']; |
|
39 | + } |
|
40 | + $content = $this->contentObject->cObjGetSingle($theValue, $theConf); |
|
41 | 41 | |
42 | - $myContent = $this->breakContent(strip_tags($content)); |
|
43 | - if (strlen($myContent) > 1) { |
|
44 | - if (substr($myContent, 0, 1) == '|' && substr($myContent, -1) == '|') { |
|
45 | - $myContent = substr($myContent, 1, strlen($myContent) - 2); |
|
46 | - } |
|
47 | - } |
|
42 | + $myContent = $this->breakContent(strip_tags($content)); |
|
43 | + if (strlen($myContent) > 1) { |
|
44 | + if (substr($myContent, 0, 1) == '|' && substr($myContent, -1) == '|') { |
|
45 | + $myContent = substr($myContent, 1, strlen($myContent) - 2); |
|
46 | + } |
|
47 | + } |
|
48 | 48 | |
49 | - if (!is_array($theConf) || strlen($theConf['plainType']) < 2) { |
|
50 | - $defaultOutput = $this->configuration['defaultOutput']; |
|
51 | - if ($defaultOutput && $myName) { |
|
52 | - $lines[] = str_replace('###CType###', $this->contentObject->data['CType'] . ': "' . $this->contentObject->data['list_type'] . '"; plugin: "' . $myName . '"; plainType: "' . (is_array($theConf) ? $theConf['plainType'] : '') . '"', $defaultOutput); |
|
53 | - } |
|
54 | - } |
|
49 | + if (!is_array($theConf) || strlen($theConf['plainType']) < 2) { |
|
50 | + $defaultOutput = $this->configuration['defaultOutput']; |
|
51 | + if ($defaultOutput && $myName) { |
|
52 | + $lines[] = str_replace('###CType###', $this->contentObject->data['CType'] . ': "' . $this->contentObject->data['list_type'] . '"; plugin: "' . $myName . '"; plainType: "' . (is_array($theConf) ? $theConf['plainType'] : '') . '"', $defaultOutput); |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | - $lines[] = $myContent; |
|
57 | - return $lines; |
|
58 | - } |
|
56 | + $lines[] = $myContent; |
|
57 | + return $lines; |
|
58 | + } |
|
59 | 59 | } |
60 | 60 | \ No newline at end of file |
@@ -26,16 +26,16 @@ discard block |
||
26 | 26 | |
27 | 27 | if (isset($template->setup['tt_content.']['list.']['20.'][$listType])) { |
28 | 28 | $theValue = $template->setup['tt_content.']['list.']['20.'][$listType]; |
29 | - $theConf = $template->setup['tt_content.']['list.']['20.'][$listType . '.']; |
|
29 | + $theConf = $template->setup['tt_content.']['list.']['20.'][$listType.'.']; |
|
30 | 30 | } else { |
31 | 31 | $tmp = explode('_pi', $listType); |
32 | 32 | if (count($tmp) < 2) { |
33 | - $myName = 'tx_' . str_replace('_', '', $tmp[0]); |
|
33 | + $myName = 'tx_'.str_replace('_', '', $tmp[0]); |
|
34 | 34 | } else { |
35 | - $myName = 'tx_' . str_replace('_', '', $tmp[0]) . '_pi' . $tmp[1]; |
|
35 | + $myName = 'tx_'.str_replace('_', '', $tmp[0]).'_pi'.$tmp[1]; |
|
36 | 36 | } |
37 | 37 | $theValue = $template->setup['plugin.'][$myName]; |
38 | - $theConf = $template->setup['plugin.'][$myName . '.']; |
|
38 | + $theConf = $template->setup['plugin.'][$myName.'.']; |
|
39 | 39 | } |
40 | 40 | $content = $this->contentObject->cObjGetSingle($theValue, $theConf); |
41 | 41 | |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | if (!is_array($theConf) || strlen($theConf['plainType']) < 2) { |
50 | 50 | $defaultOutput = $this->configuration['defaultOutput']; |
51 | 51 | if ($defaultOutput && $myName) { |
52 | - $lines[] = str_replace('###CType###', $this->contentObject->data['CType'] . ': "' . $this->contentObject->data['list_type'] . '"; plugin: "' . $myName . '"; plainType: "' . (is_array($theConf) ? $theConf['plainType'] : '') . '"', $defaultOutput); |
|
52 | + $lines[] = str_replace('###CType###', $this->contentObject->data['CType'].': "'.$this->contentObject->data['list_type'].'"; plugin: "'.$myName.'"; plainType: "'.(is_array($theConf) ? $theConf['plainType'] : '').'"', $defaultOutput); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 |
@@ -14,22 +14,22 @@ |
||
14 | 14 | */ |
15 | 15 | interface RenderingInterface { |
16 | 16 | |
17 | - /** |
|
18 | - * Set the content object and configuration |
|
19 | - * Call the renderInternal after preparation |
|
20 | - * |
|
21 | - * @param ContentObjectRenderer $contentObject |
|
22 | - * @param array $configuration |
|
23 | - * |
|
24 | - * @return array |
|
25 | - */ |
|
26 | - public function render($contentObject, $configuration); |
|
17 | + /** |
|
18 | + * Set the content object and configuration |
|
19 | + * Call the renderInternal after preparation |
|
20 | + * |
|
21 | + * @param ContentObjectRenderer $contentObject |
|
22 | + * @param array $configuration |
|
23 | + * |
|
24 | + * @return array |
|
25 | + */ |
|
26 | + public function render($contentObject, $configuration); |
|
27 | 27 | |
28 | - /** |
|
29 | - * Render the given element |
|
30 | - * |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - public function renderInternal(); |
|
28 | + /** |
|
29 | + * Render the given element |
|
30 | + * |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + public function renderInternal(); |
|
34 | 34 | |
35 | 35 | } |
36 | 36 | \ 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 |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @return string |
216 | 216 | */ |
217 | 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) { |
|
218 | + if (isset($this->tableSettings[$this->renderMode]['outer'.ucfirst($specialLine)]) && $this->tableSettings[$this->renderMode]['outer'.ucfirst($specialLine)] === FALSE) { |
|
219 | 219 | return FALSE; |
220 | 220 | } |
221 | 221 | $row = ''; |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | if ($key !== 0 || $this->tableSettings[$this->renderMode]['outerLeft']) { |
224 | 224 | $row .= $this->tableSettings[$this->renderMode]['join']; |
225 | 225 | } |
226 | - $row .= str_repeat($this->tableSettings[$this->renderMode]['x' . $charMode], ($this->tableSettings[$this->renderMode]['xSpace'] * 2) + $column_length); |
|
226 | + $row .= str_repeat($this->tableSettings[$this->renderMode]['x'.$charMode], ($this->tableSettings[$this->renderMode]['xSpace'] * 2) + $column_length); |
|
227 | 227 | } |
228 | 228 | if ($this->tableSettings[$this->renderMode]['outerRight']) { |
229 | 229 | $row .= $this->tableSettings[$this->renderMode]['join']; |