@@ -72,6 +72,9 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public $cdelim; |
74 | 74 | |
75 | + /** |
|
76 | + * @param null|string $id |
|
77 | + */ |
|
75 | 78 | public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) { |
76 | 79 | global $__DataGridCnt; |
77 | 80 | |
@@ -207,6 +210,9 @@ discard block |
||
207 | 210 | |
208 | 211 | // format column values |
209 | 212 | |
213 | + /** |
|
214 | + * @param integer $n |
|
215 | + */ |
|
210 | 216 | public function RenderRowFnc($n, $row) { |
211 | 217 | if($this->_alt == 0) { |
212 | 218 | $Style = $this->_itemStyle; |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | class DataGrid { |
14 | 14 | |
15 | - public $ds; // datasource |
|
15 | + public $ds; // datasource |
|
16 | 16 | public $id; |
17 | 17 | public $pageSize; // pager settings |
18 | 18 | public $pageNumber; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | public $colWraps; |
37 | 37 | public $colColors; |
38 | 38 | public $colTypes; // coltype1, coltype2, etc or coltype1:format1, e.g. date:%Y %m |
39 | - // data type: integer,float,currency,date |
|
39 | + // data type: integer,float,currency,date |
|
40 | 40 | |
41 | 41 | public $header; |
42 | 42 | public $footer; |
@@ -73,239 +73,239 @@ discard block |
||
73 | 73 | public $cdelim; |
74 | 74 | |
75 | 75 | public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) { |
76 | - global $__DataGridCnt; |
|
76 | + global $__DataGridCnt; |
|
77 | 77 | |
78 | - // set id |
|
79 | - $__DataGridCnt++; |
|
80 | - $this->id = $this->id ? empty($id) : "dg" . $__DataGridCnt; |
|
78 | + // set id |
|
79 | + $__DataGridCnt++; |
|
80 | + $this->id = $this->id ? empty($id) : "dg" . $__DataGridCnt; |
|
81 | 81 | |
82 | - // set datasource |
|
83 | - $this->ds = $ds; |
|
82 | + // set datasource |
|
83 | + $this->ds = $ds; |
|
84 | 84 | |
85 | - // set pager |
|
86 | - $this->pageSize = $pageSize; |
|
87 | - $this->pageNumber = $pageNumber; // by setting pager to -1 will cause pager to load it's last page number |
|
88 | - $this->pagerLocation = 'top-right'; |
|
89 | - } |
|
85 | + // set pager |
|
86 | + $this->pageSize = $pageSize; |
|
87 | + $this->pageNumber = $pageNumber; // by setting pager to -1 will cause pager to load it's last page number |
|
88 | + $this->pagerLocation = 'top-right'; |
|
89 | + } |
|
90 | 90 | |
91 | 91 | public function setDataSource($ds) { |
92 | - $this->ds = $ds; |
|
93 | - } |
|
92 | + $this->ds = $ds; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | public function render() { |
96 | - global $modx; |
|
97 | - $columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : ''; |
|
98 | - $columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : ""; |
|
99 | - $cssStyle = ($this->cssStyle) ? "style='" . $this->cssStyle . "'" : ''; |
|
100 | - $cssClass = ($this->cssClass) ? "class='" . $this->cssClass . "'" : ''; |
|
101 | - |
|
102 | - $pagerClass = ($this->pagerClass) ? "class='" . $this->pagerClass . "'" : ''; |
|
103 | - $pagerStyle = ($this->pagerStyle) ? "style='" . $this->pagerStyle . "'" : "style='background-color:#ffffff;'"; |
|
104 | - |
|
105 | - $this->_itemStyle = ($this->itemStyle) ? "style='" . $this->itemStyle . "'" : ''; |
|
106 | - $this->_itemClass = ($this->itemClass) ? "class='" . $this->itemClass . "'" : ''; |
|
107 | - $this->_altItemStyle = ($this->altItemStyle) ? "style='" . $this->altItemStyle . "'" : ''; |
|
108 | - $this->_altItemClass = ($this->altItemClass) ? "class='" . $this->altItemClass . "'" : ''; |
|
109 | - |
|
110 | - $this->_alt = 0; |
|
111 | - $this->_total = 0; |
|
112 | - |
|
113 | - $this->_isDataset = $modx->db->isResult($this->ds); // if not dataset then treat as array |
|
114 | - |
|
115 | - if(!$cssStyle && !$cssClass) { |
|
116 | - $cssStyle = "style='width:100%;border:1px solid silver;font-family:verdana,arial; font-size:11px;'"; |
|
117 | - } |
|
118 | - if(!$columnHeaderStyle && !$columnHeaderClass) { |
|
119 | - $columnHeaderStyle = "style='color:black;background-color:silver'"; |
|
120 | - } |
|
121 | - if(!$this->_itemStyle && !$this->_itemClass) { |
|
122 | - $this->_itemStyle = "style='color:black;'"; |
|
123 | - } |
|
124 | - if(!$this->_altItemStyle && !$this->_altItemClass) { |
|
125 | - $this->_altItemStyle = "style='color:black;background-color:#eeeeee'"; |
|
126 | - } |
|
127 | - |
|
128 | - if($this->_isDataset && !$this->columns) { |
|
129 | - $cols = $modx->db->numFields($this->ds); |
|
130 | - for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->db->fieldName($this->ds, $i); |
|
131 | - } |
|
132 | - |
|
133 | - // start grid |
|
134 | - $tblStart = "<table $cssClass $cssStyle cellpadding='" . (isset($this->cellPadding) ? (int) $this->cellPadding : 1) . "' cellspacing='" . (isset($this->cellSpacing) ? (int) $this->cellSpacing : 1) . "'>"; |
|
135 | - $tblEnd = "</table>"; |
|
136 | - |
|
137 | - // build column header |
|
138 | - $this->_colnames = explode((strstr($this->columns, "||") !== false ? "||" : ","), $this->columns); |
|
139 | - $this->_colwidths = explode((strstr($this->colWidths, "||") !== false ? "||" : ","), $this->colWidths); |
|
140 | - $this->_colaligns = explode((strstr($this->colAligns, "||") !== false ? "||" : ","), $this->colAligns); |
|
141 | - $this->_colwraps = explode((strstr($this->colWraps, "||") !== false ? "||" : ","), $this->colWraps); |
|
142 | - $this->_colcolors = explode((strstr($this->colColors, "||") !== false ? "||" : ","), $this->colColors); |
|
143 | - $this->_coltypes = explode((strstr($this->colTypes, "||") !== false ? "||" : ","), $this->colTypes); |
|
144 | - $this->_colcount = count($this->_colnames); |
|
145 | - if(!$this->_isDataset) { |
|
146 | - $this->ds = explode((strstr($this->ds, "||") !== false ? "||" : ","), $this->ds); |
|
147 | - $this->ds = array_chunk($this->ds, $this->_colcount); |
|
148 | - } |
|
149 | - $tblColHdr = "<thead><tr>"; |
|
150 | - for($c = 0; $c < $this->_colcount; $c++) { |
|
151 | - $name = $this->_colnames[$c]; |
|
152 | - $width = $this->_colwidths[$c]; |
|
153 | - $tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass" . ($width ? " width='$width'" : "") . ">$name</td>"; |
|
154 | - } |
|
155 | - $tblColHdr .= "</tr></thead>\n"; |
|
156 | - |
|
157 | - // build rows |
|
158 | - $rowcount = $this->_isDataset ? $modx->db->getRecordCount($this->ds) : count($this->ds); |
|
159 | - $this->_fieldnames = explode(",", $this->fields); |
|
160 | - if($rowcount == 0) { |
|
161 | - $tblRows .= "<tr><td " . $this->_itemStyle . " " . $this->_itemClass . " colspan='" . $this->_colcount . "'>" . $this->noRecordMsg . "</td></tr>\n"; |
|
162 | - } else { |
|
163 | - // render grid items |
|
164 | - if($this->pageSize <= 0) { |
|
165 | - for($r = 0; $r < $rowcount; $r++) { |
|
166 | - $row = $this->_isDataset ? $modx->db->getRow($this->ds) : $this->ds[$r]; |
|
167 | - $tblRows .= $this->RenderRowFnc($r + 1, $row); |
|
168 | - } |
|
169 | - } else { |
|
170 | - if(!$this->pager) { |
|
171 | - include_once dirname(__FILE__) . "/datasetpager.class.php"; |
|
172 | - $this->pager = new DataSetPager($this->id, $this->ds, $this->pageSize, $this->pageNumber); |
|
173 | - $this->pager->setRenderRowFnc($this); // pass this object |
|
174 | - $this->pager->cssStyle = $pagerStyle; |
|
175 | - $this->pager->cssClass = $pagerClass; |
|
176 | - } else { |
|
177 | - $this->pager->pageSize = $this->pageSize; |
|
178 | - $this->pager->pageNumber = $this->pageNumber; |
|
179 | - } |
|
180 | - |
|
181 | - $this->pager->render(); |
|
182 | - $tblRows = $this->pager->getRenderedRows(); |
|
183 | - $tblPager = $this->pager->getRenderedPager(); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - // setup header,pager and footer |
|
188 | - $o = $tblStart; |
|
189 | - $ptop = (substr($this->pagerLocation, 0, 3) == "top") || (substr($this->pagerLocation, 0, 4) == "both"); |
|
190 | - $pbot = (substr($this->pagerLocation, 0, 3) == "bot") || (substr($this->pagerLocation, 0, 4) == "both"); |
|
191 | - if($this->header) { |
|
192 | - $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->header . "</td></tr>"; |
|
193 | - } |
|
194 | - if($tblPager && $ptop) { |
|
195 | - $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
196 | - } |
|
197 | - $o .= $tblColHdr . $tblRows; |
|
198 | - if($tblPager && $pbot) { |
|
199 | - $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
200 | - } |
|
201 | - if($this->footer) { |
|
202 | - $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->footer . "</td></tr>"; |
|
203 | - } |
|
204 | - $o .= $tblEnd; |
|
205 | - return $o; |
|
206 | - } |
|
207 | - |
|
208 | - // format column values |
|
96 | + global $modx; |
|
97 | + $columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : ''; |
|
98 | + $columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : ""; |
|
99 | + $cssStyle = ($this->cssStyle) ? "style='" . $this->cssStyle . "'" : ''; |
|
100 | + $cssClass = ($this->cssClass) ? "class='" . $this->cssClass . "'" : ''; |
|
101 | + |
|
102 | + $pagerClass = ($this->pagerClass) ? "class='" . $this->pagerClass . "'" : ''; |
|
103 | + $pagerStyle = ($this->pagerStyle) ? "style='" . $this->pagerStyle . "'" : "style='background-color:#ffffff;'"; |
|
104 | + |
|
105 | + $this->_itemStyle = ($this->itemStyle) ? "style='" . $this->itemStyle . "'" : ''; |
|
106 | + $this->_itemClass = ($this->itemClass) ? "class='" . $this->itemClass . "'" : ''; |
|
107 | + $this->_altItemStyle = ($this->altItemStyle) ? "style='" . $this->altItemStyle . "'" : ''; |
|
108 | + $this->_altItemClass = ($this->altItemClass) ? "class='" . $this->altItemClass . "'" : ''; |
|
109 | + |
|
110 | + $this->_alt = 0; |
|
111 | + $this->_total = 0; |
|
112 | + |
|
113 | + $this->_isDataset = $modx->db->isResult($this->ds); // if not dataset then treat as array |
|
114 | + |
|
115 | + if(!$cssStyle && !$cssClass) { |
|
116 | + $cssStyle = "style='width:100%;border:1px solid silver;font-family:verdana,arial; font-size:11px;'"; |
|
117 | + } |
|
118 | + if(!$columnHeaderStyle && !$columnHeaderClass) { |
|
119 | + $columnHeaderStyle = "style='color:black;background-color:silver'"; |
|
120 | + } |
|
121 | + if(!$this->_itemStyle && !$this->_itemClass) { |
|
122 | + $this->_itemStyle = "style='color:black;'"; |
|
123 | + } |
|
124 | + if(!$this->_altItemStyle && !$this->_altItemClass) { |
|
125 | + $this->_altItemStyle = "style='color:black;background-color:#eeeeee'"; |
|
126 | + } |
|
127 | + |
|
128 | + if($this->_isDataset && !$this->columns) { |
|
129 | + $cols = $modx->db->numFields($this->ds); |
|
130 | + for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->db->fieldName($this->ds, $i); |
|
131 | + } |
|
132 | + |
|
133 | + // start grid |
|
134 | + $tblStart = "<table $cssClass $cssStyle cellpadding='" . (isset($this->cellPadding) ? (int) $this->cellPadding : 1) . "' cellspacing='" . (isset($this->cellSpacing) ? (int) $this->cellSpacing : 1) . "'>"; |
|
135 | + $tblEnd = "</table>"; |
|
136 | + |
|
137 | + // build column header |
|
138 | + $this->_colnames = explode((strstr($this->columns, "||") !== false ? "||" : ","), $this->columns); |
|
139 | + $this->_colwidths = explode((strstr($this->colWidths, "||") !== false ? "||" : ","), $this->colWidths); |
|
140 | + $this->_colaligns = explode((strstr($this->colAligns, "||") !== false ? "||" : ","), $this->colAligns); |
|
141 | + $this->_colwraps = explode((strstr($this->colWraps, "||") !== false ? "||" : ","), $this->colWraps); |
|
142 | + $this->_colcolors = explode((strstr($this->colColors, "||") !== false ? "||" : ","), $this->colColors); |
|
143 | + $this->_coltypes = explode((strstr($this->colTypes, "||") !== false ? "||" : ","), $this->colTypes); |
|
144 | + $this->_colcount = count($this->_colnames); |
|
145 | + if(!$this->_isDataset) { |
|
146 | + $this->ds = explode((strstr($this->ds, "||") !== false ? "||" : ","), $this->ds); |
|
147 | + $this->ds = array_chunk($this->ds, $this->_colcount); |
|
148 | + } |
|
149 | + $tblColHdr = "<thead><tr>"; |
|
150 | + for($c = 0; $c < $this->_colcount; $c++) { |
|
151 | + $name = $this->_colnames[$c]; |
|
152 | + $width = $this->_colwidths[$c]; |
|
153 | + $tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass" . ($width ? " width='$width'" : "") . ">$name</td>"; |
|
154 | + } |
|
155 | + $tblColHdr .= "</tr></thead>\n"; |
|
156 | + |
|
157 | + // build rows |
|
158 | + $rowcount = $this->_isDataset ? $modx->db->getRecordCount($this->ds) : count($this->ds); |
|
159 | + $this->_fieldnames = explode(",", $this->fields); |
|
160 | + if($rowcount == 0) { |
|
161 | + $tblRows .= "<tr><td " . $this->_itemStyle . " " . $this->_itemClass . " colspan='" . $this->_colcount . "'>" . $this->noRecordMsg . "</td></tr>\n"; |
|
162 | + } else { |
|
163 | + // render grid items |
|
164 | + if($this->pageSize <= 0) { |
|
165 | + for($r = 0; $r < $rowcount; $r++) { |
|
166 | + $row = $this->_isDataset ? $modx->db->getRow($this->ds) : $this->ds[$r]; |
|
167 | + $tblRows .= $this->RenderRowFnc($r + 1, $row); |
|
168 | + } |
|
169 | + } else { |
|
170 | + if(!$this->pager) { |
|
171 | + include_once dirname(__FILE__) . "/datasetpager.class.php"; |
|
172 | + $this->pager = new DataSetPager($this->id, $this->ds, $this->pageSize, $this->pageNumber); |
|
173 | + $this->pager->setRenderRowFnc($this); // pass this object |
|
174 | + $this->pager->cssStyle = $pagerStyle; |
|
175 | + $this->pager->cssClass = $pagerClass; |
|
176 | + } else { |
|
177 | + $this->pager->pageSize = $this->pageSize; |
|
178 | + $this->pager->pageNumber = $this->pageNumber; |
|
179 | + } |
|
180 | + |
|
181 | + $this->pager->render(); |
|
182 | + $tblRows = $this->pager->getRenderedRows(); |
|
183 | + $tblPager = $this->pager->getRenderedPager(); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + // setup header,pager and footer |
|
188 | + $o = $tblStart; |
|
189 | + $ptop = (substr($this->pagerLocation, 0, 3) == "top") || (substr($this->pagerLocation, 0, 4) == "both"); |
|
190 | + $pbot = (substr($this->pagerLocation, 0, 3) == "bot") || (substr($this->pagerLocation, 0, 4) == "both"); |
|
191 | + if($this->header) { |
|
192 | + $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->header . "</td></tr>"; |
|
193 | + } |
|
194 | + if($tblPager && $ptop) { |
|
195 | + $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
196 | + } |
|
197 | + $o .= $tblColHdr . $tblRows; |
|
198 | + if($tblPager && $pbot) { |
|
199 | + $o .= "<tr><td align='" . (substr($this->pagerLocation, -4) == "left" ? "left" : "right") . "' $pagerClass $pagerStyle colspan='" . $this->_colcount . "'>" . $tblPager . " </td></tr>"; |
|
200 | + } |
|
201 | + if($this->footer) { |
|
202 | + $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->footer . "</td></tr>"; |
|
203 | + } |
|
204 | + $o .= $tblEnd; |
|
205 | + return $o; |
|
206 | + } |
|
207 | + |
|
208 | + // format column values |
|
209 | 209 | |
210 | 210 | public function RenderRowFnc($n, $row) { |
211 | - if($this->_alt == 0) { |
|
212 | - $Style = $this->_itemStyle; |
|
213 | - $Class = $this->_itemClass; |
|
214 | - $this->_alt = 1; |
|
215 | - } else { |
|
216 | - $Style = $this->_altItemStyle; |
|
217 | - $Class = $this->_altItemClass; |
|
218 | - $this->_alt = 0; |
|
219 | - } |
|
220 | - $o = "<tr>"; |
|
221 | - for($c = 0; $c < $this->_colcount; $c++) { |
|
222 | - $colStyle = $Style; |
|
223 | - $fld = trim($this->_fieldnames[$c]); |
|
224 | - $width = isset($this->_colwidths[$c]) ? $this->_colwidths[$c] : null; |
|
225 | - $align = isset($this->_colaligns[$c]) ? $this->_colaligns[$c] : null; |
|
226 | - $color = isset($this->_colcolors[$c]) ? $this->_colcolors[$c] : null; |
|
227 | - $type = isset($this->_coltypes[$c]) ? $this->_coltypes[$c] : null; |
|
228 | - $nowrap = isset($this->_colwraps[$c]) ? $this->_colwraps[$c] : null; |
|
229 | - $value = $row[($this->_isDataset && $fld ? $fld : $c)]; |
|
230 | - if($color && $Style) { |
|
231 | - $colStyle = substr($colStyle, 0, -1) . ";background-color:$color;'"; |
|
232 | - } |
|
233 | - $value = $this->formatColumnValue($row, $value, $type, $align); |
|
234 | - $o .= "<td $colStyle $Class" . ($align ? " align='$align'" : "") . ($color ? " bgcolor='$color'" : "") . ($nowrap ? " nowrap='$nowrap'" : "") . ($width ? " width='$width'" : "") . ">$value</td>"; |
|
235 | - } |
|
236 | - $o .= "</tr>\n"; |
|
237 | - return $o; |
|
238 | - } |
|
211 | + if($this->_alt == 0) { |
|
212 | + $Style = $this->_itemStyle; |
|
213 | + $Class = $this->_itemClass; |
|
214 | + $this->_alt = 1; |
|
215 | + } else { |
|
216 | + $Style = $this->_altItemStyle; |
|
217 | + $Class = $this->_altItemClass; |
|
218 | + $this->_alt = 0; |
|
219 | + } |
|
220 | + $o = "<tr>"; |
|
221 | + for($c = 0; $c < $this->_colcount; $c++) { |
|
222 | + $colStyle = $Style; |
|
223 | + $fld = trim($this->_fieldnames[$c]); |
|
224 | + $width = isset($this->_colwidths[$c]) ? $this->_colwidths[$c] : null; |
|
225 | + $align = isset($this->_colaligns[$c]) ? $this->_colaligns[$c] : null; |
|
226 | + $color = isset($this->_colcolors[$c]) ? $this->_colcolors[$c] : null; |
|
227 | + $type = isset($this->_coltypes[$c]) ? $this->_coltypes[$c] : null; |
|
228 | + $nowrap = isset($this->_colwraps[$c]) ? $this->_colwraps[$c] : null; |
|
229 | + $value = $row[($this->_isDataset && $fld ? $fld : $c)]; |
|
230 | + if($color && $Style) { |
|
231 | + $colStyle = substr($colStyle, 0, -1) . ";background-color:$color;'"; |
|
232 | + } |
|
233 | + $value = $this->formatColumnValue($row, $value, $type, $align); |
|
234 | + $o .= "<td $colStyle $Class" . ($align ? " align='$align'" : "") . ($color ? " bgcolor='$color'" : "") . ($nowrap ? " nowrap='$nowrap'" : "") . ($width ? " width='$width'" : "") . ">$value</td>"; |
|
235 | + } |
|
236 | + $o .= "</tr>\n"; |
|
237 | + return $o; |
|
238 | + } |
|
239 | 239 | |
240 | 240 | public function formatColumnValue($row, $value, $type, &$align) { |
241 | - if(strpos($type, ":") !== false) { |
|
242 | - list($type, $type_format) = explode(":", $type, 2); |
|
243 | - } |
|
244 | - switch(strtolower($type)) { |
|
245 | - case "integer": |
|
246 | - if($align == "") { |
|
247 | - $align = "right"; |
|
248 | - } |
|
249 | - $value = number_format($value); |
|
250 | - break; |
|
251 | - |
|
252 | - case "float": |
|
253 | - if($align == "") { |
|
254 | - $align = "right"; |
|
255 | - } |
|
256 | - if(!$type_format) { |
|
257 | - $type_format = 2; |
|
258 | - } |
|
259 | - $value = number_format($value, $type_format); |
|
260 | - break; |
|
261 | - |
|
262 | - case "currency": |
|
263 | - if($align == "") { |
|
264 | - $align = "right"; |
|
265 | - } |
|
266 | - if(!$type_format) { |
|
267 | - $type_format = 2; |
|
268 | - } |
|
269 | - $value = "$" . number_format($value, $type_format); |
|
270 | - break; |
|
271 | - |
|
272 | - case "date": |
|
273 | - if($align == "") { |
|
274 | - $align = "right"; |
|
275 | - } |
|
276 | - if(!is_numeric($value)) { |
|
277 | - $value = strtotime($value); |
|
278 | - } |
|
279 | - if(!$type_format) { |
|
280 | - $type_format = "%A %d, %B %Y"; |
|
281 | - } |
|
282 | - $value = strftime($type_format, $value); |
|
283 | - break; |
|
284 | - |
|
285 | - case "boolean": |
|
286 | - if($align == '') { |
|
287 | - $align = "center"; |
|
288 | - } |
|
289 | - $value = number_format($value); |
|
290 | - if($value) { |
|
291 | - $value = '•'; |
|
292 | - } else { |
|
293 | - $value = ' '; |
|
294 | - } |
|
295 | - break; |
|
296 | - |
|
297 | - case "template": |
|
298 | - // replace [+value+] first |
|
299 | - $value = str_replace("[+value+]", $value, $type_format); |
|
300 | - // replace other [+fields+] |
|
301 | - if(strpos($value, "[+") !== false) { |
|
302 | - foreach($row as $k => $v) { |
|
303 | - $value = str_replace("[+$k+]", $v, $value); |
|
304 | - } |
|
305 | - } |
|
306 | - break; |
|
307 | - |
|
308 | - } |
|
309 | - return $value; |
|
310 | - } |
|
241 | + if(strpos($type, ":") !== false) { |
|
242 | + list($type, $type_format) = explode(":", $type, 2); |
|
243 | + } |
|
244 | + switch(strtolower($type)) { |
|
245 | + case "integer": |
|
246 | + if($align == "") { |
|
247 | + $align = "right"; |
|
248 | + } |
|
249 | + $value = number_format($value); |
|
250 | + break; |
|
251 | + |
|
252 | + case "float": |
|
253 | + if($align == "") { |
|
254 | + $align = "right"; |
|
255 | + } |
|
256 | + if(!$type_format) { |
|
257 | + $type_format = 2; |
|
258 | + } |
|
259 | + $value = number_format($value, $type_format); |
|
260 | + break; |
|
261 | + |
|
262 | + case "currency": |
|
263 | + if($align == "") { |
|
264 | + $align = "right"; |
|
265 | + } |
|
266 | + if(!$type_format) { |
|
267 | + $type_format = 2; |
|
268 | + } |
|
269 | + $value = "$" . number_format($value, $type_format); |
|
270 | + break; |
|
271 | + |
|
272 | + case "date": |
|
273 | + if($align == "") { |
|
274 | + $align = "right"; |
|
275 | + } |
|
276 | + if(!is_numeric($value)) { |
|
277 | + $value = strtotime($value); |
|
278 | + } |
|
279 | + if(!$type_format) { |
|
280 | + $type_format = "%A %d, %B %Y"; |
|
281 | + } |
|
282 | + $value = strftime($type_format, $value); |
|
283 | + break; |
|
284 | + |
|
285 | + case "boolean": |
|
286 | + if($align == '') { |
|
287 | + $align = "center"; |
|
288 | + } |
|
289 | + $value = number_format($value); |
|
290 | + if($value) { |
|
291 | + $value = '•'; |
|
292 | + } else { |
|
293 | + $value = ' '; |
|
294 | + } |
|
295 | + break; |
|
296 | + |
|
297 | + case "template": |
|
298 | + // replace [+value+] first |
|
299 | + $value = str_replace("[+value+]", $value, $type_format); |
|
300 | + // replace other [+fields+] |
|
301 | + if(strpos($value, "[+") !== false) { |
|
302 | + foreach($row as $k => $v) { |
|
303 | + $value = str_replace("[+$k+]", $v, $value); |
|
304 | + } |
|
305 | + } |
|
306 | + break; |
|
307 | + |
|
308 | + } |
|
309 | + return $value; |
|
310 | + } |
|
311 | 311 | } |
@@ -31,6 +31,9 @@ discard block |
||
31 | 31 | public $renderPagerFnc; |
32 | 32 | public $renderPagerFncArgs; |
33 | 33 | |
34 | + /** |
|
35 | + * @param boolean|string $id |
|
36 | + */ |
|
34 | 37 | public function __construct($id, $ds, $pageSize = 10, $pageNumber = -1) { |
35 | 38 | global $_PAGE; // use view state object |
36 | 39 | |
@@ -77,6 +80,9 @@ discard block |
||
77 | 80 | $this->pageSize = $ps; |
78 | 81 | } |
79 | 82 | |
83 | + /** |
|
84 | + * @param DataGrid $fncName |
|
85 | + */ |
|
80 | 86 | public function setRenderRowFnc($fncName, $args = "") { |
81 | 87 | $this->renderRowFnc = &$fncName; |
82 | 88 | $this->renderRowFncArgs = $args; // extra agruments |
@@ -12,18 +12,18 @@ discard block |
||
12 | 12 | |
13 | 13 | class DataSetPager { |
14 | 14 | |
15 | - public $ds; // datasource |
|
15 | + public $ds; // datasource |
|
16 | 16 | public $pageSize; |
17 | 17 | public $pageNumber; |
18 | 18 | public $rows; |
19 | 19 | public $pager; |
20 | 20 | public $id; |
21 | 21 | |
22 | - // normal page |
|
22 | + // normal page |
|
23 | 23 | public $pageStyle; |
24 | 24 | public $pageClass; |
25 | 25 | |
26 | - // selected page |
|
26 | + // selected page |
|
27 | 27 | public $selPageStyle; |
28 | 28 | public $selPageClass; |
29 | 29 | public $renderRowFnc; |
@@ -32,166 +32,166 @@ discard block |
||
32 | 32 | public $renderPagerFncArgs; |
33 | 33 | |
34 | 34 | public function __construct($id, $ds, $pageSize = 10, $pageNumber = -1) { |
35 | - global $_PAGE; // use view state object |
|
36 | - |
|
37 | - global $__DataSetPagerCnt; |
|
38 | - |
|
39 | - // set id |
|
40 | - $__DataSetPagerCnt++; |
|
41 | - $this->id = !empty($id) ? $id : "dsp" . $__DataSetPagerCnt; |
|
42 | - |
|
43 | - // get pagenumber |
|
44 | - // by setting pager to -1 cause pager to load it's last page number |
|
45 | - if($pageNumber == -1) { |
|
46 | - $pageNumber = 1; |
|
47 | - if(isset($_GET["dpgn" . $this->id])) { |
|
48 | - $pageNumber = $_GET["dpgn" . $this->id]; |
|
49 | - } elseif(isset($_PAGE['vs'][$id . '_dpgn'])) { |
|
50 | - $pageNumber = $_PAGE['vs'][$id . '_dpgn']; |
|
51 | - } |
|
52 | - } |
|
53 | - if(!is_numeric($pageNumber)) { |
|
54 | - $pageNumber = 1; |
|
55 | - } |
|
56 | - |
|
57 | - $this->ds = $ds; // datasource |
|
58 | - $this->pageSize = $pageSize; |
|
59 | - $this->pageNumber = $pageNumber; |
|
60 | - $this->rows = ''; |
|
61 | - $this->pager = ''; |
|
62 | - } |
|
35 | + global $_PAGE; // use view state object |
|
36 | + |
|
37 | + global $__DataSetPagerCnt; |
|
38 | + |
|
39 | + // set id |
|
40 | + $__DataSetPagerCnt++; |
|
41 | + $this->id = !empty($id) ? $id : "dsp" . $__DataSetPagerCnt; |
|
42 | + |
|
43 | + // get pagenumber |
|
44 | + // by setting pager to -1 cause pager to load it's last page number |
|
45 | + if($pageNumber == -1) { |
|
46 | + $pageNumber = 1; |
|
47 | + if(isset($_GET["dpgn" . $this->id])) { |
|
48 | + $pageNumber = $_GET["dpgn" . $this->id]; |
|
49 | + } elseif(isset($_PAGE['vs'][$id . '_dpgn'])) { |
|
50 | + $pageNumber = $_PAGE['vs'][$id . '_dpgn']; |
|
51 | + } |
|
52 | + } |
|
53 | + if(!is_numeric($pageNumber)) { |
|
54 | + $pageNumber = 1; |
|
55 | + } |
|
56 | + |
|
57 | + $this->ds = $ds; // datasource |
|
58 | + $this->pageSize = $pageSize; |
|
59 | + $this->pageNumber = $pageNumber; |
|
60 | + $this->rows = ''; |
|
61 | + $this->pager = ''; |
|
62 | + } |
|
63 | 63 | |
64 | 64 | public function getRenderedPager() { |
65 | - return $this->pager; |
|
66 | - } |
|
65 | + return $this->pager; |
|
66 | + } |
|
67 | 67 | |
68 | 68 | public function getRenderedRows() { |
69 | - return $this->rows; |
|
70 | - } |
|
69 | + return $this->rows; |
|
70 | + } |
|
71 | 71 | |
72 | 72 | public function setDataSource($ds) { |
73 | - $this->ds = $ds; |
|
74 | - } |
|
73 | + $this->ds = $ds; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | public function setPageSize($ps) { |
77 | - $this->pageSize = $ps; |
|
78 | - } |
|
77 | + $this->pageSize = $ps; |
|
78 | + } |
|
79 | 79 | |
80 | 80 | public function setRenderRowFnc($fncName, $args = "") { |
81 | - $this->renderRowFnc = &$fncName; |
|
82 | - $this->renderRowFncArgs = $args; // extra agruments |
|
81 | + $this->renderRowFnc = &$fncName; |
|
82 | + $this->renderRowFncArgs = $args; // extra agruments |
|
83 | 83 | |
84 | 84 | |
85 | - } |
|
85 | + } |
|
86 | 86 | |
87 | 87 | public function setRenderPagerFnc($fncName, $args = "") { |
88 | - $this->renderPagerFnc = $fncName; |
|
89 | - $this->renderPagerFncArgs = $args; // extra agruments |
|
90 | - } |
|
88 | + $this->renderPagerFnc = $fncName; |
|
89 | + $this->renderPagerFncArgs = $args; // extra agruments |
|
90 | + } |
|
91 | 91 | |
92 | 92 | public function render() { |
93 | - global $modx, $_PAGE; |
|
94 | - |
|
95 | - $isDataset = $modx->db->isResult($this->ds); |
|
96 | - |
|
97 | - if(!$this->selPageStyle) { |
|
98 | - $this->selPageStyle = "font-weight:bold"; |
|
99 | - } |
|
100 | - |
|
101 | - // get total number of rows |
|
102 | - $tnr = ($isDataset) ? $modx->db->getRecordCount($this->ds) : count($this->ds); |
|
103 | - |
|
104 | - // render: no records found |
|
105 | - if($tnr <= 0) { |
|
106 | - $fnc = $this->renderRowFnc; |
|
107 | - $args = $this->renderRowFncArgs; |
|
108 | - if(isset($fnc)) { |
|
109 | - if($args != "") { |
|
110 | - $this->rows .= $fnc(0, null, $args); |
|
111 | - } // if agrs was specified then we will pass three params |
|
112 | - else { |
|
113 | - $this->rows .= $fnc(0, null); |
|
114 | - } // otherwise two will be passed |
|
115 | - } |
|
116 | - return; |
|
117 | - } |
|
118 | - |
|
119 | - // get total pages |
|
120 | - $tp = ceil($tnr / $this->pageSize); |
|
121 | - if($this->pageNumber > $tp) { |
|
122 | - $this->pageNumber = 1; |
|
123 | - } |
|
124 | - |
|
125 | - // get page number |
|
126 | - $p = $this->pageNumber; |
|
127 | - |
|
128 | - // save page number to view state if available |
|
129 | - if(isset($_PAGE['vs'])) { |
|
130 | - $_PAGE['vs'][$this->id . '_dpgn'] = $p; |
|
131 | - } |
|
132 | - |
|
133 | - // render pager : renderPagerFnc($cuurentPage,$pagerNumber,$arguments=""); |
|
134 | - if($tp > 1) { |
|
135 | - $url = ''; |
|
136 | - $fnc = $this->renderPagerFnc; |
|
137 | - $args = $this->renderPagerFncArgs; |
|
138 | - if(!isset($fnc)) { |
|
139 | - if($modx->isFrontend()) { |
|
140 | - $url = $modx->makeUrl($modx->documentIdentifier, '', '', 'full') . '?'; |
|
141 | - } else { |
|
142 | - $url = $_SERVER['PHP_SELF'] . '?'; |
|
143 | - } |
|
144 | - $i = 0; |
|
145 | - foreach($_GET as $n => $v) if($n != 'dpgn' . $this->id) { |
|
146 | - $i++; |
|
147 | - $url .= (($i > 1) ? "&" : "") . "$n=$v"; |
|
148 | - } |
|
149 | - if($i >= 1) { |
|
150 | - $url .= "&"; |
|
151 | - } |
|
152 | - } |
|
153 | - for($i = 1; $i <= $tp; $i++) { |
|
154 | - if(isset($fnc)) { |
|
155 | - if($args != "") { |
|
156 | - $this->pager .= $fnc($p, $i, $args); |
|
157 | - } else { |
|
158 | - $this->pager .= $fnc($p, $i); |
|
159 | - } |
|
160 | - } else { |
|
161 | - $this->pager .= ($p == $i) ? " <span class='" . $this->selPageClass . "' style='" . $this->selPageStyle . "'>$i</span> " : " <a href='" . $url . "dpgn" . $this->id . "=$i' class='" . $this->pageClass . "' style='" . $this->pageStyle . "'>$i</a> "; |
|
162 | - } |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - // render row : renderRowFnc($rowNumber,$row,$arguments="") |
|
167 | - $fnc = $this->renderRowFnc; |
|
168 | - $args = $this->renderRowFncArgs; |
|
169 | - |
|
170 | - if(isset($fnc)) { |
|
171 | - $i = 1; |
|
172 | - $fncObject = is_object($fnc); |
|
173 | - $minitems = (($p - 1) * $this->pageSize) + 1; |
|
174 | - $maxitems = (($p - 1) * $this->pageSize) + $this->pageSize; |
|
175 | - while($i <= $maxitems && ($row = ($isDataset) ? $modx->db->getRow($this->ds) : $this->ds[$i - 1])) { |
|
176 | - if($i >= $minitems && $i <= $maxitems) { |
|
177 | - if($fncObject) { |
|
178 | - if($args != "") { |
|
179 | - $this->rows .= $fnc->RenderRowFnc($i, $row, $args); |
|
180 | - } else { |
|
181 | - $this->rows .= $fnc->RenderRowFnc($i, $row); |
|
182 | - } |
|
183 | - } else { |
|
184 | - if($args != "") { |
|
185 | - $this->rows .= $fnc($i, $row, $args); |
|
186 | - } // if agrs was specified then we wil pass three params |
|
187 | - else { |
|
188 | - $this->rows .= $fnc($i, $row); |
|
189 | - } // otherwise two will be passed |
|
190 | - } |
|
191 | - |
|
192 | - } |
|
193 | - $i++; |
|
194 | - } |
|
195 | - } |
|
196 | - } |
|
93 | + global $modx, $_PAGE; |
|
94 | + |
|
95 | + $isDataset = $modx->db->isResult($this->ds); |
|
96 | + |
|
97 | + if(!$this->selPageStyle) { |
|
98 | + $this->selPageStyle = "font-weight:bold"; |
|
99 | + } |
|
100 | + |
|
101 | + // get total number of rows |
|
102 | + $tnr = ($isDataset) ? $modx->db->getRecordCount($this->ds) : count($this->ds); |
|
103 | + |
|
104 | + // render: no records found |
|
105 | + if($tnr <= 0) { |
|
106 | + $fnc = $this->renderRowFnc; |
|
107 | + $args = $this->renderRowFncArgs; |
|
108 | + if(isset($fnc)) { |
|
109 | + if($args != "") { |
|
110 | + $this->rows .= $fnc(0, null, $args); |
|
111 | + } // if agrs was specified then we will pass three params |
|
112 | + else { |
|
113 | + $this->rows .= $fnc(0, null); |
|
114 | + } // otherwise two will be passed |
|
115 | + } |
|
116 | + return; |
|
117 | + } |
|
118 | + |
|
119 | + // get total pages |
|
120 | + $tp = ceil($tnr / $this->pageSize); |
|
121 | + if($this->pageNumber > $tp) { |
|
122 | + $this->pageNumber = 1; |
|
123 | + } |
|
124 | + |
|
125 | + // get page number |
|
126 | + $p = $this->pageNumber; |
|
127 | + |
|
128 | + // save page number to view state if available |
|
129 | + if(isset($_PAGE['vs'])) { |
|
130 | + $_PAGE['vs'][$this->id . '_dpgn'] = $p; |
|
131 | + } |
|
132 | + |
|
133 | + // render pager : renderPagerFnc($cuurentPage,$pagerNumber,$arguments=""); |
|
134 | + if($tp > 1) { |
|
135 | + $url = ''; |
|
136 | + $fnc = $this->renderPagerFnc; |
|
137 | + $args = $this->renderPagerFncArgs; |
|
138 | + if(!isset($fnc)) { |
|
139 | + if($modx->isFrontend()) { |
|
140 | + $url = $modx->makeUrl($modx->documentIdentifier, '', '', 'full') . '?'; |
|
141 | + } else { |
|
142 | + $url = $_SERVER['PHP_SELF'] . '?'; |
|
143 | + } |
|
144 | + $i = 0; |
|
145 | + foreach($_GET as $n => $v) if($n != 'dpgn' . $this->id) { |
|
146 | + $i++; |
|
147 | + $url .= (($i > 1) ? "&" : "") . "$n=$v"; |
|
148 | + } |
|
149 | + if($i >= 1) { |
|
150 | + $url .= "&"; |
|
151 | + } |
|
152 | + } |
|
153 | + for($i = 1; $i <= $tp; $i++) { |
|
154 | + if(isset($fnc)) { |
|
155 | + if($args != "") { |
|
156 | + $this->pager .= $fnc($p, $i, $args); |
|
157 | + } else { |
|
158 | + $this->pager .= $fnc($p, $i); |
|
159 | + } |
|
160 | + } else { |
|
161 | + $this->pager .= ($p == $i) ? " <span class='" . $this->selPageClass . "' style='" . $this->selPageStyle . "'>$i</span> " : " <a href='" . $url . "dpgn" . $this->id . "=$i' class='" . $this->pageClass . "' style='" . $this->pageStyle . "'>$i</a> "; |
|
162 | + } |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + // render row : renderRowFnc($rowNumber,$row,$arguments="") |
|
167 | + $fnc = $this->renderRowFnc; |
|
168 | + $args = $this->renderRowFncArgs; |
|
169 | + |
|
170 | + if(isset($fnc)) { |
|
171 | + $i = 1; |
|
172 | + $fncObject = is_object($fnc); |
|
173 | + $minitems = (($p - 1) * $this->pageSize) + 1; |
|
174 | + $maxitems = (($p - 1) * $this->pageSize) + $this->pageSize; |
|
175 | + while($i <= $maxitems && ($row = ($isDataset) ? $modx->db->getRow($this->ds) : $this->ds[$i - 1])) { |
|
176 | + if($i >= $minitems && $i <= $maxitems) { |
|
177 | + if($fncObject) { |
|
178 | + if($args != "") { |
|
179 | + $this->rows .= $fnc->RenderRowFnc($i, $row, $args); |
|
180 | + } else { |
|
181 | + $this->rows .= $fnc->RenderRowFnc($i, $row); |
|
182 | + } |
|
183 | + } else { |
|
184 | + if($args != "") { |
|
185 | + $this->rows .= $fnc($i, $row, $args); |
|
186 | + } // if agrs was specified then we wil pass three params |
|
187 | + else { |
|
188 | + $this->rows .= $fnc($i, $row); |
|
189 | + } // otherwise two will be passed |
|
190 | + } |
|
191 | + |
|
192 | + } |
|
193 | + $i++; |
|
194 | + } |
|
195 | + } |
|
196 | + } |
|
197 | 197 | } |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | * MODX_MANAGER_PATH."includes/extenders/ex_{$extname}.inc.php" |
257 | 257 | * $extname - extension name in lowercase |
258 | 258 | * |
259 | - * @param $extname |
|
259 | + * @param string $extname |
|
260 | 260 | * @param bool $reload |
261 | 261 | * @return bool |
262 | 262 | */ |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @param int $count_attempts |
300 | 300 | * @param string $type $type |
301 | 301 | * @param string $responseCode |
302 | - * @return bool |
|
302 | + * @return false|null |
|
303 | 303 | * @global string $base_url |
304 | 304 | * @global string $site_url |
305 | 305 | */ |
@@ -999,7 +999,7 @@ discard block |
||
999 | 999 | } |
1000 | 1000 | |
1001 | 1001 | /** |
1002 | - * @param $contents |
|
1002 | + * @param string $contents |
|
1003 | 1003 | * @return mixed |
1004 | 1004 | */ |
1005 | 1005 | public function RecoveryEscapedTags($contents) |
@@ -1023,7 +1023,7 @@ discard block |
||
1023 | 1023 | } |
1024 | 1024 | |
1025 | 1025 | /** |
1026 | - * @param $tstart |
|
1026 | + * @param double $tstart |
|
1027 | 1027 | * @return array |
1028 | 1028 | */ |
1029 | 1029 | public function getTimerStats($tstart) |
@@ -1775,7 +1775,7 @@ discard block |
||
1775 | 1775 | |
1776 | 1776 | /** |
1777 | 1777 | * Remove Comment-Tags from output like <!--@- Comment -@--> |
1778 | - * @param $content |
|
1778 | + * @param string $content |
|
1779 | 1779 | * @param string $left |
1780 | 1780 | * @param string $right |
1781 | 1781 | * @return mixed |
@@ -1948,7 +1948,7 @@ discard block |
||
1948 | 1948 | /** |
1949 | 1949 | * Run snippets as per the tags in $documentSource and replace the tags with the returned values. |
1950 | 1950 | * |
1951 | - * @param $content |
|
1951 | + * @param string $content |
|
1952 | 1952 | * @return string |
1953 | 1953 | * @internal param string $documentSource |
1954 | 1954 | */ |
@@ -2980,7 +2980,7 @@ discard block |
||
2980 | 2980 | |
2981 | 2981 | /** |
2982 | 2982 | * @param $templateID |
2983 | - * @return mixed |
|
2983 | + * @return string |
|
2984 | 2984 | */ |
2985 | 2985 | public function _getTemplateCodeFromDB($templateID) |
2986 | 2986 | { |
@@ -3021,9 +3021,9 @@ discard block |
||
3021 | 3021 | } |
3022 | 3022 | |
3023 | 3023 | /** |
3024 | - * @param $id |
|
3024 | + * @param integer $id |
|
3025 | 3025 | * @param int $top |
3026 | - * @return mixed |
|
3026 | + * @return string |
|
3027 | 3027 | */ |
3028 | 3028 | public function getUltimateParentId($id, $top = 0) |
3029 | 3029 | { |
@@ -3354,7 +3354,7 @@ discard block |
||
3354 | 3354 | * |
3355 | 3355 | * @param int $type Types: 1=template, 2=tv, 3=chunk, 4=snippet, 5=plugin, 6=module, 7=resource, 8=role |
3356 | 3356 | * @param int $id Element- / Resource-id |
3357 | - * @return bool |
|
3357 | + * @return false|null |
|
3358 | 3358 | */ |
3359 | 3359 | public function lockElement($type, $id) |
3360 | 3360 | { |
@@ -3376,7 +3376,7 @@ discard block |
||
3376 | 3376 | * @param int $type Types: 1=template, 2=tv, 3=chunk, 4=snippet, 5=plugin, 6=module, 7=resource, 8=role |
3377 | 3377 | * @param int $id Element- / Resource-id |
3378 | 3378 | * @param bool $includeAllUsers true = Deletes not only own user-locks |
3379 | - * @return bool |
|
3379 | + * @return false|null |
|
3380 | 3380 | */ |
3381 | 3381 | public function unlockElement($type, $id, $includeAllUsers = false) |
3382 | 3382 | { |
@@ -3484,7 +3484,7 @@ discard block |
||
3484 | 3484 | * @param array $params |
3485 | 3485 | * @param string $msg |
3486 | 3486 | * @param array $files |
3487 | - * @return mixed |
|
3487 | + * @return boolean |
|
3488 | 3488 | */ |
3489 | 3489 | public function sendmail($params = array(), $msg = '', $files = array()) |
3490 | 3490 | { |
@@ -3980,7 +3980,7 @@ discard block |
||
3980 | 3980 | * |
3981 | 3981 | * @param string $type |
3982 | 3982 | * @param bool $report |
3983 | - * @return bool |
|
3983 | + * @return boolean|null |
|
3984 | 3984 | */ |
3985 | 3985 | public function clearCache($type = '', $report = false) |
3986 | 3986 | { |
@@ -5024,7 +5024,7 @@ discard block |
||
5024 | 5024 | * Returns a record for the web user |
5025 | 5025 | * |
5026 | 5026 | * @param int $uid |
5027 | - * @return boolean|string |
|
5027 | + * @return boolean|null |
|
5028 | 5028 | */ |
5029 | 5029 | public function getWebUserInfo($uid) |
5030 | 5030 | { |
@@ -5322,7 +5322,7 @@ discard block |
||
5322 | 5322 | * Remove event listener - only for use within the current execution cycle |
5323 | 5323 | * |
5324 | 5324 | * @param string $evtName |
5325 | - * @return boolean |
|
5325 | + * @return false|null |
|
5326 | 5326 | */ |
5327 | 5327 | public function removeEventListener($evtName) |
5328 | 5328 | { |
@@ -5346,7 +5346,7 @@ discard block |
||
5346 | 5346 | * |
5347 | 5347 | * @param string $evtName |
5348 | 5348 | * @param array $extParams Parameters available to plugins. Each array key will be the PHP variable name, and the array value will be the variable value. |
5349 | - * @return boolean|array |
|
5349 | + * @return false|null |
|
5350 | 5350 | */ |
5351 | 5351 | public function invokeEvent($evtName, $extParams = array()) |
5352 | 5352 | { |
@@ -5767,7 +5767,7 @@ discard block |
||
5767 | 5767 | |
5768 | 5768 | /** |
5769 | 5769 | * @param string $string |
5770 | - * @return mixed|string |
|
5770 | + * @return string |
|
5771 | 5771 | */ |
5772 | 5772 | public function removeSanitizeSeed($string = '') |
5773 | 5773 | { |
@@ -5782,7 +5782,7 @@ discard block |
||
5782 | 5782 | |
5783 | 5783 | /** |
5784 | 5784 | * @param string $content |
5785 | - * @return mixed|string |
|
5785 | + * @return string |
|
5786 | 5786 | */ |
5787 | 5787 | public function cleanUpMODXTags($content = '') |
5788 | 5788 | { |
@@ -5945,7 +5945,7 @@ discard block |
||
5945 | 5945 | |
5946 | 5946 | /** |
5947 | 5947 | * @param string $str |
5948 | - * @return bool|mixed|string |
|
5948 | + * @return string |
|
5949 | 5949 | */ |
5950 | 5950 | public function atBindFileContent($str = '') |
5951 | 5951 | { |
@@ -5996,8 +5996,8 @@ discard block |
||
5996 | 5996 | } |
5997 | 5997 | |
5998 | 5998 | /** |
5999 | - * @param $str |
|
6000 | - * @return bool|string |
|
5999 | + * @param string $str |
|
6000 | + * @return false|string |
|
6001 | 6001 | */ |
6002 | 6002 | public function getExtFromFilename($str) |
6003 | 6003 | { |
@@ -6025,7 +6025,7 @@ discard block |
||
6025 | 6025 | * @param string $text Error message |
6026 | 6026 | * @param string $file File where the error was detected |
6027 | 6027 | * @param string $line Line number within $file |
6028 | - * @return boolean |
|
6028 | + * @return boolean|null |
|
6029 | 6029 | */ |
6030 | 6030 | public function phpError($nr, $text, $file, $line) |
6031 | 6031 | { |
@@ -6077,7 +6077,7 @@ discard block |
||
6077 | 6077 | * @param string $text |
6078 | 6078 | * @param string $line |
6079 | 6079 | * @param string $output |
6080 | - * @return bool |
|
6080 | + * @return null|boolean |
|
6081 | 6081 | */ |
6082 | 6082 | public function messageQuit($msg = 'unspecified error', $query = '', $is_error = true, $nr = '', $file = '', $source = '', $text = '', $line = '', $output = '') |
6083 | 6083 | { |
@@ -6499,7 +6499,7 @@ discard block |
||
6499 | 6499 | |
6500 | 6500 | /** |
6501 | 6501 | * @param string $str |
6502 | - * @return bool|mixed|string |
|
6502 | + * @return string |
|
6503 | 6503 | */ |
6504 | 6504 | public function atBindInclude($str = '') |
6505 | 6505 | { |
@@ -6550,7 +6550,7 @@ discard block |
||
6550 | 6550 | * @param $str |
6551 | 6551 | * @param int $flags |
6552 | 6552 | * @param string $encode |
6553 | - * @return mixed |
|
6553 | + * @return string |
|
6554 | 6554 | */ |
6555 | 6555 | public function htmlspecialchars($str, $flags = ENT_COMPAT, $encode = '') |
6556 | 6556 | { |
@@ -6559,7 +6559,7 @@ discard block |
||
6559 | 6559 | } |
6560 | 6560 | |
6561 | 6561 | /** |
6562 | - * @param $string |
|
6562 | + * @param string $string |
|
6563 | 6563 | * @param bool $returnData |
6564 | 6564 | * @return bool|mixed |
6565 | 6565 | */ |
@@ -102,6 +102,9 @@ discard block |
||
102 | 102 | return $rs; |
103 | 103 | } |
104 | 104 | |
105 | + /** |
|
106 | + * @param string $filepath |
|
107 | + */ |
|
105 | 108 | public function makeFile($docid, $filepath) |
106 | 109 | { |
107 | 110 | global $modx,$_lang; |
@@ -250,6 +253,9 @@ discard block |
||
250 | 253 | return implode("\n", $this->output); |
251 | 254 | } |
252 | 255 | |
256 | + /** |
|
257 | + * @param string $url |
|
258 | + */ |
|
253 | 259 | public function curl_get_contents($url, $timeout = 30 ) |
254 | 260 | { |
255 | 261 | if(!function_exists('curl_init')) return @file_get_contents($url); |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class EXPORT_SITE |
3 | 3 | { |
4 | - public $targetDir; |
|
4 | + public $targetDir; |
|
5 | 5 | public $generate_mode; |
6 | 6 | public $total; |
7 | 7 | public $count; |
@@ -13,246 +13,246 @@ discard block |
||
13 | 13 | public $dirCheckCount = 0; |
14 | 14 | |
15 | 15 | public function __construct() |
16 | - { |
|
17 | - global $modx; |
|
18 | - |
|
19 | - if(!defined('MODX_BASE_PATH')) return false; |
|
20 | - $this->exportstart = $this->get_mtime(); |
|
21 | - $this->count = 0; |
|
22 | - $this->setUrlMode(); |
|
23 | - $this->generate_mode = 'crawl'; |
|
24 | - $this->targetDir = $modx->config['base_path'] . 'temp/export'; |
|
25 | - if(!isset($this->total)) $this->getTotal(); |
|
26 | - } |
|
16 | + { |
|
17 | + global $modx; |
|
18 | + |
|
19 | + if(!defined('MODX_BASE_PATH')) return false; |
|
20 | + $this->exportstart = $this->get_mtime(); |
|
21 | + $this->count = 0; |
|
22 | + $this->setUrlMode(); |
|
23 | + $this->generate_mode = 'crawl'; |
|
24 | + $this->targetDir = $modx->config['base_path'] . 'temp/export'; |
|
25 | + if(!isset($this->total)) $this->getTotal(); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | public function setExportDir($dir) |
29 | - { |
|
30 | - $dir = str_replace('\\','/',$dir); |
|
31 | - $dir = rtrim($dir, '/'); |
|
32 | - $this->targetDir = $dir; |
|
33 | - } |
|
29 | + { |
|
30 | + $dir = str_replace('\\','/',$dir); |
|
31 | + $dir = rtrim($dir, '/'); |
|
32 | + $this->targetDir = $dir; |
|
33 | + } |
|
34 | 34 | |
35 | 35 | public function get_mtime() |
36 | - { |
|
37 | - $mtime = microtime(); |
|
38 | - $mtime = explode(' ', $mtime); |
|
39 | - $mtime = $mtime[1] + $mtime[0]; |
|
40 | - return $mtime; |
|
41 | - } |
|
36 | + { |
|
37 | + $mtime = microtime(); |
|
38 | + $mtime = explode(' ', $mtime); |
|
39 | + $mtime = $mtime[1] + $mtime[0]; |
|
40 | + return $mtime; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | public function setUrlMode() |
44 | - { |
|
45 | - global $modx; |
|
46 | - |
|
47 | - if($modx->config['friendly_urls']==0) |
|
48 | - { |
|
49 | - $modx->config['friendly_urls'] = 1; |
|
50 | - $modx->config['use_alias_path'] = 1; |
|
51 | - $modx->clearCache('full'); |
|
52 | - } |
|
53 | - $modx->config['make_folders'] = '1'; |
|
54 | - } |
|
44 | + { |
|
45 | + global $modx; |
|
46 | + |
|
47 | + if($modx->config['friendly_urls']==0) |
|
48 | + { |
|
49 | + $modx->config['friendly_urls'] = 1; |
|
50 | + $modx->config['use_alias_path'] = 1; |
|
51 | + $modx->clearCache('full'); |
|
52 | + } |
|
53 | + $modx->config['make_folders'] = '1'; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | public function getTotal($ignore_ids='', $noncache='0') |
57 | - { |
|
58 | - global $modx; |
|
59 | - $tbl_site_content = $modx->getFullTableName('site_content'); |
|
60 | - |
|
61 | - $ignore_ids = array_filter(array_map('intval', explode(',', $ignore_ids))); |
|
62 | - if(count($ignore_ids)>0) |
|
63 | - { |
|
64 | - $ignore_ids = "AND NOT id IN ('".implode("','", $ignore_ids)."')"; |
|
65 | - } else { |
|
66 | - $ignore_ids = ''; |
|
67 | - } |
|
68 | - |
|
69 | - $this->ignore_ids = $ignore_ids; |
|
70 | - |
|
71 | - $noncache = ($noncache == 1) ? '' : 'AND cacheable=1'; |
|
72 | - $where = "deleted=0 AND ((published=1 AND type='document') OR (isfolder=1)) {$noncache} {$ignore_ids}"; |
|
73 | - $rs = $modx->db->select('count(id)',$tbl_site_content,$where); |
|
74 | - $this->total = $modx->db->getValue($rs); |
|
75 | - return $this->total; |
|
76 | - } |
|
57 | + { |
|
58 | + global $modx; |
|
59 | + $tbl_site_content = $modx->getFullTableName('site_content'); |
|
60 | + |
|
61 | + $ignore_ids = array_filter(array_map('intval', explode(',', $ignore_ids))); |
|
62 | + if(count($ignore_ids)>0) |
|
63 | + { |
|
64 | + $ignore_ids = "AND NOT id IN ('".implode("','", $ignore_ids)."')"; |
|
65 | + } else { |
|
66 | + $ignore_ids = ''; |
|
67 | + } |
|
68 | + |
|
69 | + $this->ignore_ids = $ignore_ids; |
|
70 | + |
|
71 | + $noncache = ($noncache == 1) ? '' : 'AND cacheable=1'; |
|
72 | + $where = "deleted=0 AND ((published=1 AND type='document') OR (isfolder=1)) {$noncache} {$ignore_ids}"; |
|
73 | + $rs = $modx->db->select('count(id)',$tbl_site_content,$where); |
|
74 | + $this->total = $modx->db->getValue($rs); |
|
75 | + return $this->total; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | public function removeDirectoryAll($directory='') |
79 | - { |
|
80 | - $rs = false; |
|
81 | - if(empty($directory)) $directory = $this->targetDir; |
|
82 | - $directory = rtrim($directory,'/'); |
|
83 | - // if the path is not valid or is not a directory ... |
|
84 | - if(empty($directory)) return false; |
|
85 | - if(strpos($directory,MODX_BASE_PATH)===false) return $rs; |
|
86 | - |
|
87 | - if(!is_dir($directory)) return $rs; |
|
88 | - elseif(!is_readable($directory)) return $rs; |
|
89 | - else |
|
90 | - { |
|
91 | - $files = glob($directory . '/*'); |
|
92 | - if(!empty($files)) |
|
93 | - { |
|
94 | - foreach($files as $path) |
|
95 | - { |
|
79 | + { |
|
80 | + $rs = false; |
|
81 | + if(empty($directory)) $directory = $this->targetDir; |
|
82 | + $directory = rtrim($directory,'/'); |
|
83 | + // if the path is not valid or is not a directory ... |
|
84 | + if(empty($directory)) return false; |
|
85 | + if(strpos($directory,MODX_BASE_PATH)===false) return $rs; |
|
86 | + |
|
87 | + if(!is_dir($directory)) return $rs; |
|
88 | + elseif(!is_readable($directory)) return $rs; |
|
89 | + else |
|
90 | + { |
|
91 | + $files = glob($directory . '/*'); |
|
92 | + if(!empty($files)) |
|
93 | + { |
|
94 | + foreach($files as $path) |
|
95 | + { |
|
96 | 96 | $rs = is_dir($path) ? $this->removeDirectoryAll($path) : unlink($path); |
97 | - } |
|
98 | - } |
|
99 | - } |
|
100 | - if($directory !== $this->targetDir) $rs = rmdir($directory); |
|
97 | + } |
|
98 | + } |
|
99 | + } |
|
100 | + if($directory !== $this->targetDir) $rs = rmdir($directory); |
|
101 | 101 | |
102 | - return $rs; |
|
103 | - } |
|
102 | + return $rs; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | public function makeFile($docid, $filepath) |
106 | - { |
|
107 | - global $modx,$_lang; |
|
108 | - $file_permission = octdec($modx->config['new_file_permissions']); |
|
109 | - if($this->generate_mode==='direct') |
|
110 | - { |
|
111 | - $back_lang = $_lang; |
|
112 | - $src = $modx->executeParser($docid); |
|
113 | - |
|
114 | - $_lang = $back_lang; |
|
115 | - } |
|
116 | - else $src = $this->curl_get_contents(MODX_SITE_URL . "index.php?id={$docid}"); |
|
117 | - |
|
118 | - |
|
119 | - if($src !== false) |
|
120 | - { |
|
121 | - if($this->repl_before!==$this->repl_after) $src = str_replace($this->repl_before,$this->repl_after,$src); |
|
122 | - $result = file_put_contents($filepath,$src); |
|
123 | - if($result!==false) @chmod($filepath, $file_permission); |
|
124 | - |
|
125 | - if($result !== false) return 'success'; |
|
126 | - else return 'failed_no_write'; |
|
127 | - } |
|
128 | - else return 'failed_no_retrieve'; |
|
129 | - } |
|
106 | + { |
|
107 | + global $modx,$_lang; |
|
108 | + $file_permission = octdec($modx->config['new_file_permissions']); |
|
109 | + if($this->generate_mode==='direct') |
|
110 | + { |
|
111 | + $back_lang = $_lang; |
|
112 | + $src = $modx->executeParser($docid); |
|
113 | + |
|
114 | + $_lang = $back_lang; |
|
115 | + } |
|
116 | + else $src = $this->curl_get_contents(MODX_SITE_URL . "index.php?id={$docid}"); |
|
117 | + |
|
118 | + |
|
119 | + if($src !== false) |
|
120 | + { |
|
121 | + if($this->repl_before!==$this->repl_after) $src = str_replace($this->repl_before,$this->repl_after,$src); |
|
122 | + $result = file_put_contents($filepath,$src); |
|
123 | + if($result!==false) @chmod($filepath, $file_permission); |
|
124 | + |
|
125 | + if($result !== false) return 'success'; |
|
126 | + else return 'failed_no_write'; |
|
127 | + } |
|
128 | + else return 'failed_no_retrieve'; |
|
129 | + } |
|
130 | 130 | |
131 | 131 | public function getFileName($docid, $alias='', $prefix, $suffix) |
132 | - { |
|
133 | - global $modx; |
|
134 | - |
|
135 | - if($alias==='') $filename = $prefix.$docid.$suffix; |
|
136 | - else |
|
137 | - { |
|
138 | - if($modx->config['suffix_mode']==='1' && strpos($alias, '.')!==false) |
|
139 | - { |
|
140 | - $suffix = ''; |
|
141 | - } |
|
142 | - $filename = $prefix.$alias.$suffix; |
|
143 | - } |
|
144 | - return $filename; |
|
145 | - } |
|
132 | + { |
|
133 | + global $modx; |
|
134 | + |
|
135 | + if($alias==='') $filename = $prefix.$docid.$suffix; |
|
136 | + else |
|
137 | + { |
|
138 | + if($modx->config['suffix_mode']==='1' && strpos($alias, '.')!==false) |
|
139 | + { |
|
140 | + $suffix = ''; |
|
141 | + } |
|
142 | + $filename = $prefix.$alias.$suffix; |
|
143 | + } |
|
144 | + return $filename; |
|
145 | + } |
|
146 | 146 | |
147 | 147 | public function run($parent=0) |
148 | - { |
|
149 | - global $_lang; |
|
150 | - global $modx; |
|
148 | + { |
|
149 | + global $_lang; |
|
150 | + global $modx; |
|
151 | 151 | |
152 | - $tbl_site_content = $modx->getFullTableName('site_content'); |
|
152 | + $tbl_site_content = $modx->getFullTableName('site_content'); |
|
153 | 153 | |
154 | - $ignore_ids = $this->ignore_ids; |
|
155 | - $dirpath = $this->targetDir . '/'; |
|
154 | + $ignore_ids = $this->ignore_ids; |
|
155 | + $dirpath = $this->targetDir . '/'; |
|
156 | 156 | |
157 | - $prefix = $modx->config['friendly_url_prefix']; |
|
158 | - $suffix = $modx->config['friendly_url_suffix']; |
|
157 | + $prefix = $modx->config['friendly_url_prefix']; |
|
158 | + $suffix = $modx->config['friendly_url_suffix']; |
|
159 | 159 | |
160 | - $tpl = ' <span class="[+status+]">[+msg1+]</span> [+msg2+]</span>'; |
|
161 | - $ph = array(); |
|
160 | + $tpl = ' <span class="[+status+]">[+msg1+]</span> [+msg2+]</span>'; |
|
161 | + $ph = array(); |
|
162 | 162 | |
163 | - $ph['status'] = 'fail'; |
|
164 | - $ph['msg1'] = $_lang['export_site_failed']; |
|
165 | - $ph['msg2'] = $_lang["export_site_failed_no_write"] . ' - ' . $dirpath; |
|
166 | - $msg_failed_no_write = $this->parsePlaceholder($tpl,$ph); |
|
163 | + $ph['status'] = 'fail'; |
|
164 | + $ph['msg1'] = $_lang['export_site_failed']; |
|
165 | + $ph['msg2'] = $_lang["export_site_failed_no_write"] . ' - ' . $dirpath; |
|
166 | + $msg_failed_no_write = $this->parsePlaceholder($tpl,$ph); |
|
167 | 167 | |
168 | - $ph['msg2'] = $_lang["export_site_failed_no_retrieve"]; |
|
169 | - $msg_failed_no_retrieve = $this->parsePlaceholder($tpl,$ph); |
|
168 | + $ph['msg2'] = $_lang["export_site_failed_no_retrieve"]; |
|
169 | + $msg_failed_no_retrieve = $this->parsePlaceholder($tpl,$ph); |
|
170 | 170 | |
171 | - $ph['status'] = 'success'; |
|
172 | - $ph['msg1'] = $_lang['export_site_success']; |
|
173 | - $ph['msg2'] = ''; |
|
174 | - $msg_success = $this->parsePlaceholder($tpl,$ph); |
|
171 | + $ph['status'] = 'success'; |
|
172 | + $ph['msg1'] = $_lang['export_site_success']; |
|
173 | + $ph['msg2'] = ''; |
|
174 | + $msg_success = $this->parsePlaceholder($tpl,$ph); |
|
175 | 175 | |
176 | - $ph['msg2'] = $_lang['export_site_success_skip_doc']; |
|
177 | - $msg_success_skip_doc = $this->parsePlaceholder($tpl,$ph); |
|
176 | + $ph['msg2'] = $_lang['export_site_success_skip_doc']; |
|
177 | + $msg_success_skip_doc = $this->parsePlaceholder($tpl,$ph); |
|
178 | 178 | |
179 | - $ph['msg2'] = $_lang['export_site_success_skip_dir']; |
|
180 | - $msg_success_skip_dir = $this->parsePlaceholder($tpl,$ph); |
|
179 | + $ph['msg2'] = $_lang['export_site_success_skip_dir']; |
|
180 | + $msg_success_skip_dir = $this->parsePlaceholder($tpl,$ph); |
|
181 | 181 | |
182 | - $fields = "id, alias, pagetitle, isfolder, (content = '' AND template = 0) AS wasNull, published"; |
|
183 | - $noncache = $_POST['includenoncache']==1 ? '' : 'AND cacheable=1'; |
|
184 | - $where = "parent = '{$parent}' AND deleted=0 AND ((published=1 AND type='document') OR (isfolder=1)) {$noncache} {$ignore_ids}"; |
|
185 | - $rs = $modx->db->select($fields,$tbl_site_content,$where); |
|
182 | + $fields = "id, alias, pagetitle, isfolder, (content = '' AND template = 0) AS wasNull, published"; |
|
183 | + $noncache = $_POST['includenoncache']==1 ? '' : 'AND cacheable=1'; |
|
184 | + $where = "parent = '{$parent}' AND deleted=0 AND ((published=1 AND type='document') OR (isfolder=1)) {$noncache} {$ignore_ids}"; |
|
185 | + $rs = $modx->db->select($fields,$tbl_site_content,$where); |
|
186 | 186 | |
187 | - $ph = array(); |
|
188 | - $ph['total'] = $this->total; |
|
189 | - $folder_permission = octdec($modx->config['new_folder_permissions']); |
|
190 | - while($row = $modx->db->getRow($rs)) |
|
191 | - { |
|
192 | - $this->count++; |
|
187 | + $ph = array(); |
|
188 | + $ph['total'] = $this->total; |
|
189 | + $folder_permission = octdec($modx->config['new_folder_permissions']); |
|
190 | + while($row = $modx->db->getRow($rs)) |
|
191 | + { |
|
192 | + $this->count++; |
|
193 | 193 | $filename = ''; |
194 | - $row['count'] = $this->count; |
|
195 | - $row['url'] = $modx->makeUrl($row['id']); |
|
196 | - |
|
197 | - if (!$row['wasNull']) |
|
198 | - { // needs writing a document |
|
199 | - $docname = $this->getFileName($row['id'], $row['alias'], $prefix, $suffix); |
|
200 | - $filename = $dirpath.$docname; |
|
201 | - if (!is_file($filename)) |
|
202 | - { |
|
203 | - if($row['published']==='1') |
|
204 | - { |
|
205 | - $status = $this->makeFile($row['id'], $filename); |
|
206 | - switch($status) |
|
207 | - { |
|
208 | - case 'failed_no_write' : |
|
194 | + $row['count'] = $this->count; |
|
195 | + $row['url'] = $modx->makeUrl($row['id']); |
|
196 | + |
|
197 | + if (!$row['wasNull']) |
|
198 | + { // needs writing a document |
|
199 | + $docname = $this->getFileName($row['id'], $row['alias'], $prefix, $suffix); |
|
200 | + $filename = $dirpath.$docname; |
|
201 | + if (!is_file($filename)) |
|
202 | + { |
|
203 | + if($row['published']==='1') |
|
204 | + { |
|
205 | + $status = $this->makeFile($row['id'], $filename); |
|
206 | + switch($status) |
|
207 | + { |
|
208 | + case 'failed_no_write' : |
|
209 | 209 | $row['status'] = $msg_failed_no_write; |
210 | 210 | break; |
211 | - case 'failed_no_retrieve': |
|
211 | + case 'failed_no_retrieve': |
|
212 | 212 | $row['status'] = $msg_failed_no_retrieve; |
213 | 213 | break; |
214 | - default: |
|
214 | + default: |
|
215 | 215 | $row['status'] = $msg_success; |
216 | - } |
|
217 | - } |
|
218 | - else $row['status'] = $msg_failed_no_retrieve; |
|
219 | - } |
|
220 | - else $row['status'] = $msg_success_skip_doc; |
|
221 | - $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row); |
|
222 | - } |
|
223 | - else |
|
224 | - { |
|
225 | - $row['status'] = $msg_success_skip_dir; |
|
226 | - $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row); |
|
227 | - } |
|
228 | - if ($row['isfolder']==='1' && ($modx->config['suffix_mode']!=='1' || strpos($row['alias'],'.')===false)) |
|
229 | - { // needs making a folder |
|
230 | - $end_dir = ($row['alias']!=='') ? $row['alias'] : $row['id']; |
|
231 | - $dir_path = $dirpath . $end_dir; |
|
232 | - if(strpos($dir_path,MODX_BASE_PATH)===false) return FALSE; |
|
233 | - if (!is_dir($dir_path)) |
|
234 | - { |
|
235 | - if (is_file($dir_path)) @unlink($dir_path); |
|
236 | - mkdir($dir_path); |
|
237 | - @chmod($dir_path, $folder_permission); |
|
238 | - |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - if($modx->config['make_folders']==='1' && $row['published']==='1') |
|
243 | - { |
|
244 | - if( ! empty($filename) && is_file($filename)) rename($filename,$dir_path . '/index.html'); |
|
245 | - } |
|
246 | - $this->targetDir = $dir_path; |
|
247 | - $this->run($row['id']); |
|
248 | - } |
|
249 | - } |
|
250 | - return implode("\n", $this->output); |
|
251 | - } |
|
216 | + } |
|
217 | + } |
|
218 | + else $row['status'] = $msg_failed_no_retrieve; |
|
219 | + } |
|
220 | + else $row['status'] = $msg_success_skip_doc; |
|
221 | + $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row); |
|
222 | + } |
|
223 | + else |
|
224 | + { |
|
225 | + $row['status'] = $msg_success_skip_dir; |
|
226 | + $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row); |
|
227 | + } |
|
228 | + if ($row['isfolder']==='1' && ($modx->config['suffix_mode']!=='1' || strpos($row['alias'],'.')===false)) |
|
229 | + { // needs making a folder |
|
230 | + $end_dir = ($row['alias']!=='') ? $row['alias'] : $row['id']; |
|
231 | + $dir_path = $dirpath . $end_dir; |
|
232 | + if(strpos($dir_path,MODX_BASE_PATH)===false) return FALSE; |
|
233 | + if (!is_dir($dir_path)) |
|
234 | + { |
|
235 | + if (is_file($dir_path)) @unlink($dir_path); |
|
236 | + mkdir($dir_path); |
|
237 | + @chmod($dir_path, $folder_permission); |
|
238 | + |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + if($modx->config['make_folders']==='1' && $row['published']==='1') |
|
243 | + { |
|
244 | + if( ! empty($filename) && is_file($filename)) rename($filename,$dir_path . '/index.html'); |
|
245 | + } |
|
246 | + $this->targetDir = $dir_path; |
|
247 | + $this->run($row['id']); |
|
248 | + } |
|
249 | + } |
|
250 | + return implode("\n", $this->output); |
|
251 | + } |
|
252 | 252 | |
253 | 253 | public function curl_get_contents($url, $timeout = 30 ) |
254 | 254 | { |
255 | - if(!function_exists('curl_init')) return @file_get_contents($url); |
|
255 | + if(!function_exists('curl_init')) return @file_get_contents($url); |
|
256 | 256 | |
257 | 257 | $ch = curl_init(); |
258 | 258 | curl_setopt($ch, CURLOPT_URL, $url); |
@@ -269,12 +269,12 @@ discard block |
||
269 | 269 | |
270 | 270 | public function parsePlaceholder($tpl,$ph=array()) |
271 | 271 | { |
272 | - foreach($ph as $k=>$v) |
|
273 | - { |
|
274 | - $k = "[+{$k}+]"; |
|
275 | - $tpl = str_replace($k,$v,$tpl); |
|
276 | - } |
|
277 | - return $tpl; |
|
272 | + foreach($ph as $k=>$v) |
|
273 | + { |
|
274 | + $k = "[+{$k}+]"; |
|
275 | + $tpl = str_replace($k,$v,$tpl); |
|
276 | + } |
|
277 | + return $tpl; |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | /** |
86 | 86 | * Sets the class attribute of the main HTML TABLE. |
87 | 87 | * |
88 | - * @param $value A class for the main HTML TABLE. |
|
88 | + * @param string $value A class for the main HTML TABLE. |
|
89 | 89 | */ |
90 | 90 | public function setTableClass($value) { |
91 | 91 | $this->tableClass= $value; |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | /** |
131 | 131 | * Sets the class attribute of regular table rows. |
132 | 132 | * |
133 | - * @param $value A class for regular table rows. |
|
133 | + * @param string $value A class for regular table rows. |
|
134 | 134 | */ |
135 | 135 | public function setRowRegularClass($value) { |
136 | 136 | $this->rowRegularClass= $value; |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | /** |
140 | 140 | * Sets the class attribute of alternate table rows. |
141 | 141 | * |
142 | - * @param $value A class for alternate table rows. |
|
142 | + * @param string $value A class for alternate table rows. |
|
143 | 143 | */ |
144 | 144 | public function setRowAlternateClass($value) { |
145 | 145 | $this->rowAlternateClass= $value; |
@@ -215,6 +215,7 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @param $value An Array of column widths in the order of the keys in the |
217 | 217 | * source table array. |
218 | + * @param string[] $widthArray |
|
218 | 219 | */ |
219 | 220 | public function setColumnWidths($widthArray) { |
220 | 221 | $this->columnWidths= $widthArray; |
@@ -242,7 +243,7 @@ discard block |
||
242 | 243 | /** |
243 | 244 | * Retrieves the width of a specific table column by index position. |
244 | 245 | * |
245 | - * @param $columnPosition The index of the column to get the width for. |
|
246 | + * @param integer $columnPosition The index of the column to get the width for. |
|
246 | 247 | */ |
247 | 248 | public function getColumnWidth($columnPosition) { |
248 | 249 | $currentWidth= ''; |
@@ -256,6 +257,7 @@ discard block |
||
256 | 257 | * Determines what class the current row should have applied. |
257 | 258 | * |
258 | 259 | * @param $value The position of the current row being rendered. |
260 | + * @param integer $position |
|
259 | 261 | */ |
260 | 262 | public function determineRowClass($position) { |
261 | 263 | switch ($this->rowAlternatingScheme) { |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * @author Jason Coward <[email protected]> (MODX) |
10 | 10 | */ |
11 | 11 | class MakeTable { |
12 | - public $actionField; |
|
12 | + public $actionField; |
|
13 | 13 | public $cellAction; |
14 | 14 | public $linkAction; |
15 | 15 | public $tableWidth; |
@@ -34,343 +34,343 @@ discard block |
||
34 | 34 | public $extra; |
35 | 35 | |
36 | 36 | public function __construct() { |
37 | - $this->fieldHeaders= array(); |
|
38 | - $this->excludeFields= array(); |
|
39 | - $this->actionField= ''; |
|
40 | - $this->cellAction= ''; |
|
41 | - $this->linkAction= ''; |
|
42 | - $this->tableWidth= ''; |
|
43 | - $this->tableClass= ''; |
|
44 | - $this->rowHeaderClass= ''; |
|
45 | - $this->columnHeaderClass= ''; |
|
46 | - $this->rowRegularClass= ''; |
|
47 | - $this->rowAlternateClass= 'alt'; |
|
48 | - $this->formName= 'tableForm'; |
|
49 | - $this->formAction= '[~[*id*]~]'; |
|
50 | - $this->formElementName= ''; |
|
51 | - $this->formElementType= ''; |
|
52 | - $this->rowAlternatingScheme= 'EVEN'; |
|
53 | - $this->allOption= 0; |
|
54 | - $this->selectedValues= array(); |
|
55 | - $this->extra= ''; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Sets the default link href for all cells in the table. |
|
60 | - * |
|
61 | - * @param $value A URL to execute when table cells are clicked. |
|
62 | - */ |
|
37 | + $this->fieldHeaders= array(); |
|
38 | + $this->excludeFields= array(); |
|
39 | + $this->actionField= ''; |
|
40 | + $this->cellAction= ''; |
|
41 | + $this->linkAction= ''; |
|
42 | + $this->tableWidth= ''; |
|
43 | + $this->tableClass= ''; |
|
44 | + $this->rowHeaderClass= ''; |
|
45 | + $this->columnHeaderClass= ''; |
|
46 | + $this->rowRegularClass= ''; |
|
47 | + $this->rowAlternateClass= 'alt'; |
|
48 | + $this->formName= 'tableForm'; |
|
49 | + $this->formAction= '[~[*id*]~]'; |
|
50 | + $this->formElementName= ''; |
|
51 | + $this->formElementType= ''; |
|
52 | + $this->rowAlternatingScheme= 'EVEN'; |
|
53 | + $this->allOption= 0; |
|
54 | + $this->selectedValues= array(); |
|
55 | + $this->extra= ''; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Sets the default link href for all cells in the table. |
|
60 | + * |
|
61 | + * @param $value A URL to execute when table cells are clicked. |
|
62 | + */ |
|
63 | 63 | public function setCellAction($value) { |
64 | - $this->cellAction= $this->prepareLink($value); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Sets the default link href for the text presented in a cell. |
|
69 | - * |
|
70 | - * @param $value A URL to execute when text within table cells are clicked. |
|
71 | - */ |
|
64 | + $this->cellAction= $this->prepareLink($value); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Sets the default link href for the text presented in a cell. |
|
69 | + * |
|
70 | + * @param $value A URL to execute when text within table cells are clicked. |
|
71 | + */ |
|
72 | 72 | public function setLinkAction($value) { |
73 | - $this->linkAction= $this->prepareLink($value); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Sets the width attribute of the main HTML TABLE. |
|
78 | - * |
|
79 | - * @param $value A valid width attribute for the HTML TABLE tag |
|
80 | - */ |
|
73 | + $this->linkAction= $this->prepareLink($value); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Sets the width attribute of the main HTML TABLE. |
|
78 | + * |
|
79 | + * @param $value A valid width attribute for the HTML TABLE tag |
|
80 | + */ |
|
81 | 81 | public function setTableWidth($value) { |
82 | - $this->tableWidth= $value; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Sets the class attribute of the main HTML TABLE. |
|
87 | - * |
|
88 | - * @param $value A class for the main HTML TABLE. |
|
89 | - */ |
|
82 | + $this->tableWidth= $value; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Sets the class attribute of the main HTML TABLE. |
|
87 | + * |
|
88 | + * @param $value A class for the main HTML TABLE. |
|
89 | + */ |
|
90 | 90 | public function setTableClass($value) { |
91 | - $this->tableClass= $value; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Sets the id attribute of the main HTML TABLE. |
|
96 | - * |
|
97 | - * @param $value A class for the main HTML TABLE. |
|
98 | - */ |
|
91 | + $this->tableClass= $value; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Sets the id attribute of the main HTML TABLE. |
|
96 | + * |
|
97 | + * @param $value A class for the main HTML TABLE. |
|
98 | + */ |
|
99 | 99 | public function setTableID($value) { |
100 | - $this->tableID= $value; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Sets the class attribute of the table header row. |
|
105 | - * |
|
106 | - * @param $value A class for the table header row. |
|
107 | - */ |
|
100 | + $this->tableID= $value; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Sets the class attribute of the table header row. |
|
105 | + * |
|
106 | + * @param $value A class for the table header row. |
|
107 | + */ |
|
108 | 108 | public function setRowHeaderClass($value) { |
109 | - $this->rowHeaderClass= $value; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Sets the class attribute of the table header row. |
|
114 | - * |
|
115 | - * @param $value A class for the table header row. |
|
116 | - */ |
|
109 | + $this->rowHeaderClass= $value; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Sets the class attribute of the table header row. |
|
114 | + * |
|
115 | + * @param $value A class for the table header row. |
|
116 | + */ |
|
117 | 117 | public function setThHeaderClass($value) { |
118 | - $this->thClass= $value; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Sets the class attribute of the column header row. |
|
123 | - * |
|
124 | - * @param $value A class for the column header row. |
|
125 | - */ |
|
118 | + $this->thClass= $value; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Sets the class attribute of the column header row. |
|
123 | + * |
|
124 | + * @param $value A class for the column header row. |
|
125 | + */ |
|
126 | 126 | public function setColumnHeaderClass($value) { |
127 | - $this->columnHeaderClass= $value; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Sets the class attribute of regular table rows. |
|
132 | - * |
|
133 | - * @param $value A class for regular table rows. |
|
134 | - */ |
|
127 | + $this->columnHeaderClass= $value; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Sets the class attribute of regular table rows. |
|
132 | + * |
|
133 | + * @param $value A class for regular table rows. |
|
134 | + */ |
|
135 | 135 | public function setRowRegularClass($value) { |
136 | - $this->rowRegularClass= $value; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Sets the class attribute of alternate table rows. |
|
141 | - * |
|
142 | - * @param $value A class for alternate table rows. |
|
143 | - */ |
|
136 | + $this->rowRegularClass= $value; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Sets the class attribute of alternate table rows. |
|
141 | + * |
|
142 | + * @param $value A class for alternate table rows. |
|
143 | + */ |
|
144 | 144 | public function setRowAlternateClass($value) { |
145 | - $this->rowAlternateClass= $value; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Sets the type of INPUT form element to be presented as the first column. |
|
150 | - * |
|
151 | - * @param $value Indicates the INPUT form element type attribute. |
|
152 | - */ |
|
145 | + $this->rowAlternateClass= $value; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Sets the type of INPUT form element to be presented as the first column. |
|
150 | + * |
|
151 | + * @param $value Indicates the INPUT form element type attribute. |
|
152 | + */ |
|
153 | 153 | public function setFormElementType($value) { |
154 | - $this->formElementType= $value; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Sets the name of the INPUT form element to be presented as the first column. |
|
159 | - * |
|
160 | - * @param $value Indicates the INPUT form element name attribute. |
|
161 | - */ |
|
154 | + $this->formElementType= $value; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Sets the name of the INPUT form element to be presented as the first column. |
|
159 | + * |
|
160 | + * @param $value Indicates the INPUT form element name attribute. |
|
161 | + */ |
|
162 | 162 | public function setFormElementName($value) { |
163 | - $this->formElementName= $value; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Sets the name of the FORM to wrap the table in when a form element has |
|
168 | - * been indicated. |
|
169 | - * |
|
170 | - * @param $value Indicates the FORM name attribute. |
|
171 | - */ |
|
163 | + $this->formElementName= $value; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Sets the name of the FORM to wrap the table in when a form element has |
|
168 | + * been indicated. |
|
169 | + * |
|
170 | + * @param $value Indicates the FORM name attribute. |
|
171 | + */ |
|
172 | 172 | public function setFormName($value) { |
173 | - $this->formName= $value; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Sets the action of the FORM element. |
|
178 | - * |
|
179 | - * @param $value Indicates the FORM action attribute. |
|
180 | - */ |
|
173 | + $this->formName= $value; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Sets the action of the FORM element. |
|
178 | + * |
|
179 | + * @param $value Indicates the FORM action attribute. |
|
180 | + */ |
|
181 | 181 | public function setFormAction($value) { |
182 | - $this->formAction= $value; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Excludes fields from the table by array key. |
|
187 | - * |
|
188 | - * @param $value An Array of field keys to exclude from the table. |
|
189 | - */ |
|
182 | + $this->formAction= $value; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Excludes fields from the table by array key. |
|
187 | + * |
|
188 | + * @param $value An Array of field keys to exclude from the table. |
|
189 | + */ |
|
190 | 190 | public function setExcludeFields($value) { |
191 | - $this->excludeFields= $value; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Sets the table to provide alternate row colors using ODD or EVEN rows |
|
196 | - * |
|
197 | - * @param $value 'ODD' or 'EVEN' to indicate the alternate row scheme. |
|
198 | - */ |
|
191 | + $this->excludeFields= $value; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Sets the table to provide alternate row colors using ODD or EVEN rows |
|
196 | + * |
|
197 | + * @param $value 'ODD' or 'EVEN' to indicate the alternate row scheme. |
|
198 | + */ |
|
199 | 199 | public function setRowAlternatingScheme($value) { |
200 | - $this->rowAlternatingScheme= $value; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Sets the default field value to be used when appending query parameters |
|
205 | - * to link actions. |
|
206 | - * |
|
207 | - * @param $value The key of the field to add as a query string parameter. |
|
208 | - */ |
|
200 | + $this->rowAlternatingScheme= $value; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Sets the default field value to be used when appending query parameters |
|
205 | + * to link actions. |
|
206 | + * |
|
207 | + * @param $value The key of the field to add as a query string parameter. |
|
208 | + */ |
|
209 | 209 | public function setActionFieldName($value) { |
210 | - $this->actionField= $value; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Sets the width attribute of each column in the array. |
|
215 | - * |
|
216 | - * @param $value An Array of column widths in the order of the keys in the |
|
217 | - * source table array. |
|
218 | - */ |
|
210 | + $this->actionField= $value; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Sets the width attribute of each column in the array. |
|
215 | + * |
|
216 | + * @param $value An Array of column widths in the order of the keys in the |
|
217 | + * source table array. |
|
218 | + */ |
|
219 | 219 | public function setColumnWidths($widthArray) { |
220 | - $this->columnWidths= $widthArray; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * An optional array of values that can be preselected when using |
|
225 | - * |
|
226 | - * @param $value Indicates the INPUT form element type attribute. |
|
227 | - */ |
|
220 | + $this->columnWidths= $widthArray; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * An optional array of values that can be preselected when using |
|
225 | + * |
|
226 | + * @param $value Indicates the INPUT form element type attribute. |
|
227 | + */ |
|
228 | 228 | public function setSelectedValues($valueArray) { |
229 | - $this->selectedValues= $valueArray; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Sets extra content to be presented following the table (but within |
|
234 | - * the form, if a form is being rendered with the table). |
|
235 | - * |
|
236 | - * @param $value A string of additional content. |
|
237 | - */ |
|
229 | + $this->selectedValues= $valueArray; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Sets extra content to be presented following the table (but within |
|
234 | + * the form, if a form is being rendered with the table). |
|
235 | + * |
|
236 | + * @param $value A string of additional content. |
|
237 | + */ |
|
238 | 238 | public function setExtra($value) { |
239 | - $this->extra= $value; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Retrieves the width of a specific table column by index position. |
|
244 | - * |
|
245 | - * @param $columnPosition The index of the column to get the width for. |
|
246 | - */ |
|
239 | + $this->extra= $value; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Retrieves the width of a specific table column by index position. |
|
244 | + * |
|
245 | + * @param $columnPosition The index of the column to get the width for. |
|
246 | + */ |
|
247 | 247 | public function getColumnWidth($columnPosition) { |
248 | - $currentWidth= ''; |
|
249 | - if (is_array($this->columnWidths)) { |
|
250 | - $currentWidth= $this->columnWidths[$columnPosition] ? ' width="'.$this->columnWidths[$columnPosition].'" ' : ''; |
|
251 | - } |
|
252 | - return $currentWidth; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Determines what class the current row should have applied. |
|
257 | - * |
|
258 | - * @param $value The position of the current row being rendered. |
|
259 | - */ |
|
248 | + $currentWidth= ''; |
|
249 | + if (is_array($this->columnWidths)) { |
|
250 | + $currentWidth= $this->columnWidths[$columnPosition] ? ' width="'.$this->columnWidths[$columnPosition].'" ' : ''; |
|
251 | + } |
|
252 | + return $currentWidth; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Determines what class the current row should have applied. |
|
257 | + * |
|
258 | + * @param $value The position of the current row being rendered. |
|
259 | + */ |
|
260 | 260 | public function determineRowClass($position) { |
261 | - switch ($this->rowAlternatingScheme) { |
|
262 | - case 'ODD' : |
|
263 | - $modRemainder= 1; |
|
264 | - break; |
|
265 | - case 'EVEN' : |
|
266 | - $modRemainder= 0; |
|
267 | - break; |
|
268 | - } |
|
269 | - if ($position % 2 == $modRemainder) { |
|
270 | - $currentClass= $this->rowRegularClass; |
|
271 | - } else { |
|
272 | - $currentClass= $this->rowAlternateClass; |
|
273 | - } |
|
274 | - return ' class="'.$currentClass.'"'; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Generates an onclick action applied to the current cell, to execute |
|
279 | - * any specified cell actions. |
|
280 | - * |
|
281 | - * @param $value Indicates the INPUT form element type attribute. |
|
282 | - */ |
|
261 | + switch ($this->rowAlternatingScheme) { |
|
262 | + case 'ODD' : |
|
263 | + $modRemainder= 1; |
|
264 | + break; |
|
265 | + case 'EVEN' : |
|
266 | + $modRemainder= 0; |
|
267 | + break; |
|
268 | + } |
|
269 | + if ($position % 2 == $modRemainder) { |
|
270 | + $currentClass= $this->rowRegularClass; |
|
271 | + } else { |
|
272 | + $currentClass= $this->rowAlternateClass; |
|
273 | + } |
|
274 | + return ' class="'.$currentClass.'"'; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Generates an onclick action applied to the current cell, to execute |
|
279 | + * any specified cell actions. |
|
280 | + * |
|
281 | + * @param $value Indicates the INPUT form element type attribute. |
|
282 | + */ |
|
283 | 283 | public function getCellAction($currentActionFieldValue) { |
284 | - if ($this->cellAction) { |
|
285 | - $cellAction= ' onClick="javascript:window.location=\''.$this->cellAction.$this->actionField.'='.urlencode($currentActionFieldValue).'\'" '; |
|
286 | - } |
|
287 | - return $cellAction; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Generates the cell content, including any specified action fields values. |
|
292 | - * |
|
293 | - * @param $currentActionFieldValue The value to be applied to the link action. |
|
294 | - * @param $value The value of the cell. |
|
295 | - */ |
|
284 | + if ($this->cellAction) { |
|
285 | + $cellAction= ' onClick="javascript:window.location=\''.$this->cellAction.$this->actionField.'='.urlencode($currentActionFieldValue).'\'" '; |
|
286 | + } |
|
287 | + return $cellAction; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Generates the cell content, including any specified action fields values. |
|
292 | + * |
|
293 | + * @param $currentActionFieldValue The value to be applied to the link action. |
|
294 | + * @param $value The value of the cell. |
|
295 | + */ |
|
296 | 296 | public function createCellText($currentActionFieldValue, $value) { |
297 | - $cell .= $value; |
|
298 | - if ($this->linkAction) { |
|
299 | - $cell= '<a href="'.$this->linkAction.$this->actionField.'='.urlencode($currentActionFieldValue).'">'.$cell.'</a>'; |
|
300 | - } |
|
301 | - return $cell; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Sets an option to generate a check all link when checkbox is indicated |
|
306 | - * as the table formElementType. |
|
307 | - */ |
|
297 | + $cell .= $value; |
|
298 | + if ($this->linkAction) { |
|
299 | + $cell= '<a href="'.$this->linkAction.$this->actionField.'='.urlencode($currentActionFieldValue).'">'.$cell.'</a>'; |
|
300 | + } |
|
301 | + return $cell; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Sets an option to generate a check all link when checkbox is indicated |
|
306 | + * as the table formElementType. |
|
307 | + */ |
|
308 | 308 | public function setAllOption() { |
309 | - $this->allOption= 1; |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Function to prepare a link generated in the table cell/link actions. |
|
314 | - * |
|
315 | - * @param $value Indicates the INPUT form element type attribute. |
|
316 | - */ |
|
309 | + $this->allOption= 1; |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Function to prepare a link generated in the table cell/link actions. |
|
314 | + * |
|
315 | + * @param $value Indicates the INPUT form element type attribute. |
|
316 | + */ |
|
317 | 317 | public function prepareLink($link) { |
318 | - if (strstr($link, '?')) { |
|
319 | - $end= '&'; |
|
320 | - } else { |
|
321 | - $end= '?'; |
|
322 | - } |
|
323 | - return $link.$end; |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Generates the table content. |
|
328 | - * |
|
329 | - * @param $fieldsArray The associative array representing the table rows |
|
330 | - * and columns. |
|
331 | - * @param $fieldHeadersArray An optional array of values for providing |
|
332 | - * alternative field headers; this is an associative arrays of keys from |
|
333 | - * the $fieldsArray where the values represent the alt heading content |
|
334 | - * for each column. |
|
335 | - */ |
|
318 | + if (strstr($link, '?')) { |
|
319 | + $end= '&'; |
|
320 | + } else { |
|
321 | + $end= '?'; |
|
322 | + } |
|
323 | + return $link.$end; |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Generates the table content. |
|
328 | + * |
|
329 | + * @param $fieldsArray The associative array representing the table rows |
|
330 | + * and columns. |
|
331 | + * @param $fieldHeadersArray An optional array of values for providing |
|
332 | + * alternative field headers; this is an associative arrays of keys from |
|
333 | + * the $fieldsArray where the values represent the alt heading content |
|
334 | + * for each column. |
|
335 | + */ |
|
336 | 336 | public function create($fieldsArray, $fieldHeadersArray=array(),$linkpage="") { |
337 | - global $_lang; |
|
338 | - if (is_array($fieldsArray)) { |
|
339 | - $i= 0; |
|
340 | - foreach ($fieldsArray as $fieldName => $fieldValue) { |
|
341 | - $table .= "\t<tr".$this->determineRowClass($i).">\n"; |
|
342 | - $currentActionFieldValue= $fieldValue[$this->actionField]; |
|
343 | - if (is_array($this->selectedValues)) { |
|
344 | - $isChecked= array_search($currentActionFieldValue, $this->selectedValues)===false? 0 : 1; |
|
345 | - } else { |
|
346 | - $isChecked= false; |
|
347 | - } |
|
348 | - $table .= $this->addFormField($currentActionFieldValue, $isChecked); |
|
349 | - $colPosition= 0; |
|
350 | - foreach ($fieldValue as $key => $value) { |
|
351 | - if (!in_array($key, $this->excludeFields)) { |
|
352 | - $table .= "\t\t<td".$this->getCellAction($currentActionFieldValue).">"; |
|
353 | - $table .= $this->createCellText($currentActionFieldValue, $value); |
|
354 | - $table .= "</td>\n"; |
|
355 | - if ($i == 0) { |
|
356 | - if (empty ($header) && $this->formElementType) { |
|
357 | - $header .= "\t\t<th style=\"width:32px\" ".($this->thClass ? 'class="'.$this->thClass.'"' : '').">". ($this->allOption ? '<a href="javascript:clickAll()">all</a>' : '')."</th>\n"; |
|
358 | - } |
|
359 | - $headerText= array_key_exists($key, $fieldHeadersArray)? $fieldHeadersArray[$key]: $key; |
|
360 | - $header .= "\t\t<th".$this->getColumnWidth($colPosition).($this->thClass ? ' class="'.$this->thClass.'" ' : '').">".$headerText."</th>\n"; |
|
361 | - } |
|
362 | - $colPosition ++; |
|
363 | - } |
|
364 | - } |
|
365 | - $i ++; |
|
366 | - $table .= "\t</tr>\n"; |
|
367 | - } |
|
368 | - $table= "\n".'<table'. ($this->tableWidth ? ' width="'.$this->tableWidth.'"' : ''). ($this->tableClass ? ' class="'.$this->tableClass.'"' : ''). ($this->tableID ? ' id="'.$this->tableID.'"' : '').">\n". ($header ? "\t<thead>\n\t<tr class=\"".$this->rowHeaderClass."\">\n".$header."\t</tr>\n\t</thead>\n" : '').$table."</table>\n"; |
|
369 | - if ($this->formElementType) { |
|
370 | - $table= "\n".'<form id="'.$this->formName.'" name="'.$this->formName.'" action="'.$this->formAction.'" method="POST">'.$table; |
|
371 | - } |
|
372 | - if (strlen($this->pageNav) > 1) {//changed to display the pagination if exists. |
|
373 | - /* commented this part because of cookie |
|
337 | + global $_lang; |
|
338 | + if (is_array($fieldsArray)) { |
|
339 | + $i= 0; |
|
340 | + foreach ($fieldsArray as $fieldName => $fieldValue) { |
|
341 | + $table .= "\t<tr".$this->determineRowClass($i).">\n"; |
|
342 | + $currentActionFieldValue= $fieldValue[$this->actionField]; |
|
343 | + if (is_array($this->selectedValues)) { |
|
344 | + $isChecked= array_search($currentActionFieldValue, $this->selectedValues)===false? 0 : 1; |
|
345 | + } else { |
|
346 | + $isChecked= false; |
|
347 | + } |
|
348 | + $table .= $this->addFormField($currentActionFieldValue, $isChecked); |
|
349 | + $colPosition= 0; |
|
350 | + foreach ($fieldValue as $key => $value) { |
|
351 | + if (!in_array($key, $this->excludeFields)) { |
|
352 | + $table .= "\t\t<td".$this->getCellAction($currentActionFieldValue).">"; |
|
353 | + $table .= $this->createCellText($currentActionFieldValue, $value); |
|
354 | + $table .= "</td>\n"; |
|
355 | + if ($i == 0) { |
|
356 | + if (empty ($header) && $this->formElementType) { |
|
357 | + $header .= "\t\t<th style=\"width:32px\" ".($this->thClass ? 'class="'.$this->thClass.'"' : '').">". ($this->allOption ? '<a href="javascript:clickAll()">all</a>' : '')."</th>\n"; |
|
358 | + } |
|
359 | + $headerText= array_key_exists($key, $fieldHeadersArray)? $fieldHeadersArray[$key]: $key; |
|
360 | + $header .= "\t\t<th".$this->getColumnWidth($colPosition).($this->thClass ? ' class="'.$this->thClass.'" ' : '').">".$headerText."</th>\n"; |
|
361 | + } |
|
362 | + $colPosition ++; |
|
363 | + } |
|
364 | + } |
|
365 | + $i ++; |
|
366 | + $table .= "\t</tr>\n"; |
|
367 | + } |
|
368 | + $table= "\n".'<table'. ($this->tableWidth ? ' width="'.$this->tableWidth.'"' : ''). ($this->tableClass ? ' class="'.$this->tableClass.'"' : ''). ($this->tableID ? ' id="'.$this->tableID.'"' : '').">\n". ($header ? "\t<thead>\n\t<tr class=\"".$this->rowHeaderClass."\">\n".$header."\t</tr>\n\t</thead>\n" : '').$table."</table>\n"; |
|
369 | + if ($this->formElementType) { |
|
370 | + $table= "\n".'<form id="'.$this->formName.'" name="'.$this->formName.'" action="'.$this->formAction.'" method="POST">'.$table; |
|
371 | + } |
|
372 | + if (strlen($this->pageNav) > 1) {//changed to display the pagination if exists. |
|
373 | + /* commented this part because of cookie |
|
374 | 374 | $table .= '<div id="max-display-records" ><select style="display:inline" onchange="javascript:updatePageSize(this[this.selectedIndex].value);">'; |
375 | 375 | $pageSizes= array (10, 25, 50, 100, 250); |
376 | 376 | for ($i= 0; $i < count($pageSizes); $i ++) { |
@@ -381,12 +381,12 @@ discard block |
||
381 | 381 | |
382 | 382 | $table .= '</select>'.$_lang["pagination_table_perpage"].'</div>'; |
383 | 383 | */ |
384 | - $table .= '<div id="pagination" class="paginate">'.$_lang["pagination_table_gotopage"].'<ul>'.$this->pageNav.'</ul></div>'; |
|
385 | - //$table .= '<script language="javascript">function updatePageSize(size){window.location = \''.$this->prepareLink($linkpage).'pageSize=\'+size;}</script>'; |
|
384 | + $table .= '<div id="pagination" class="paginate">'.$_lang["pagination_table_gotopage"].'<ul>'.$this->pageNav.'</ul></div>'; |
|
385 | + //$table .= '<script language="javascript">function updatePageSize(size){window.location = \''.$this->prepareLink($linkpage).'pageSize=\'+size;}</script>'; |
|
386 | 386 | |
387 | - } |
|
388 | - if ($this->allOption) { |
|
389 | - $table .= ' |
|
387 | + } |
|
388 | + if ($this->allOption) { |
|
389 | + $table .= ' |
|
390 | 390 | <script language="javascript"> |
391 | 391 | toggled = 0; |
392 | 392 | function clickAll() { |
@@ -399,134 +399,134 @@ discard block |
||
399 | 399 | toggled = (toggled?0:1); |
400 | 400 | } |
401 | 401 | </script>'; |
402 | - } |
|
403 | - if ($this->formElementType) { |
|
404 | - if ($this->extra) { |
|
405 | - $table.= "\n".$this->extra."\n"; |
|
406 | - } |
|
407 | - $table.= "\n".'</form>'."\n"; |
|
408 | - } |
|
409 | - return $table; |
|
410 | - } |
|
411 | - } |
|
412 | - |
|
413 | - /** |
|
414 | - * Generates optional paging navigation controls for the table. |
|
415 | - * |
|
416 | - * @param $numRecords The number of records to show per page. |
|
417 | - * @param $qs An optional query string to be appended to the paging links |
|
418 | - */ |
|
402 | + } |
|
403 | + if ($this->formElementType) { |
|
404 | + if ($this->extra) { |
|
405 | + $table.= "\n".$this->extra."\n"; |
|
406 | + } |
|
407 | + $table.= "\n".'</form>'."\n"; |
|
408 | + } |
|
409 | + return $table; |
|
410 | + } |
|
411 | + } |
|
412 | + |
|
413 | + /** |
|
414 | + * Generates optional paging navigation controls for the table. |
|
415 | + * |
|
416 | + * @param $numRecords The number of records to show per page. |
|
417 | + * @param $qs An optional query string to be appended to the paging links |
|
418 | + */ |
|
419 | 419 | public function createPagingNavigation($numRecords, $qs='') { |
420 | - global $_lang; |
|
421 | - $currentPage= (is_numeric($_GET['page']) ? $_GET['page'] : 1); |
|
422 | - $numPages= ceil($numRecords / MAX_DISPLAY_RECORDS_NUM); |
|
423 | - if ($numPages > 1) { |
|
424 | - $currentURL= empty($qs)? '': '?'.$qs; |
|
425 | - if ($currentPage > 6) { |
|
426 | - $nav .= $this->createPageLink($currentURL, 1, $_lang["pagination_table_first"]); |
|
427 | - } |
|
428 | - if ($currentPage != 1) { |
|
429 | - $nav .= $this->createPageLink($currentURL, $currentPage -1, '<<'); |
|
430 | - } |
|
431 | - $offset= -4 + ($currentPage < 5 ? (5 - $currentPage) : 0); |
|
432 | - $i= 1; |
|
433 | - while ($i < 10 && ($currentPage + $offset <= $numPages)) { |
|
434 | - if ($currentPage == $currentPage + $offset) |
|
435 | - $nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset, true); |
|
436 | - else |
|
437 | - $nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset); |
|
438 | - $i ++; |
|
439 | - $offset ++; |
|
440 | - } |
|
441 | - if ($currentPage < $numPages) { |
|
442 | - $nav .= $this->createPageLink($currentURL, $currentPage +1, '>>'); |
|
443 | - } |
|
444 | - if ($currentPage != $numPages) { |
|
445 | - $nav .= $this->createPageLink($currentURL, $numPages, $_lang["pagination_table_last"]); |
|
446 | - } |
|
447 | - } |
|
448 | - $this->pageNav= ' '.$nav; |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Creates an individual page link for the paging navigation. |
|
453 | - * |
|
454 | - * @param $link The link for the page, defaulted to the current document. |
|
455 | - * @param $pageNum The page number of the link. |
|
456 | - * @param $displayText The text of the link. |
|
457 | - * @param $currentPage Indicates if the link is to the current page. |
|
458 | - * @param $qs And optional query string to be appended to the link. |
|
459 | - */ |
|
420 | + global $_lang; |
|
421 | + $currentPage= (is_numeric($_GET['page']) ? $_GET['page'] : 1); |
|
422 | + $numPages= ceil($numRecords / MAX_DISPLAY_RECORDS_NUM); |
|
423 | + if ($numPages > 1) { |
|
424 | + $currentURL= empty($qs)? '': '?'.$qs; |
|
425 | + if ($currentPage > 6) { |
|
426 | + $nav .= $this->createPageLink($currentURL, 1, $_lang["pagination_table_first"]); |
|
427 | + } |
|
428 | + if ($currentPage != 1) { |
|
429 | + $nav .= $this->createPageLink($currentURL, $currentPage -1, '<<'); |
|
430 | + } |
|
431 | + $offset= -4 + ($currentPage < 5 ? (5 - $currentPage) : 0); |
|
432 | + $i= 1; |
|
433 | + while ($i < 10 && ($currentPage + $offset <= $numPages)) { |
|
434 | + if ($currentPage == $currentPage + $offset) |
|
435 | + $nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset, true); |
|
436 | + else |
|
437 | + $nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset); |
|
438 | + $i ++; |
|
439 | + $offset ++; |
|
440 | + } |
|
441 | + if ($currentPage < $numPages) { |
|
442 | + $nav .= $this->createPageLink($currentURL, $currentPage +1, '>>'); |
|
443 | + } |
|
444 | + if ($currentPage != $numPages) { |
|
445 | + $nav .= $this->createPageLink($currentURL, $numPages, $_lang["pagination_table_last"]); |
|
446 | + } |
|
447 | + } |
|
448 | + $this->pageNav= ' '.$nav; |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Creates an individual page link for the paging navigation. |
|
453 | + * |
|
454 | + * @param $link The link for the page, defaulted to the current document. |
|
455 | + * @param $pageNum The page number of the link. |
|
456 | + * @param $displayText The text of the link. |
|
457 | + * @param $currentPage Indicates if the link is to the current page. |
|
458 | + * @param $qs And optional query string to be appended to the link. |
|
459 | + */ |
|
460 | 460 | public function createPageLink($link='', $pageNum, $displayText, $currentPage=false, $qs='') { |
461 | - global $modx; |
|
462 | - $orderBy= !empty($_GET['orderby'])? '&orderby=' . $_GET['orderby']: ''; |
|
463 | - $orderDir= !empty($_GET['orderdir'])? '&orderdir=' . $_GET['orderdir']: ''; |
|
464 | - if (!empty($qs)) $qs= "?$qs"; |
|
465 | - $link= empty($link)? $modx->makeUrl($modx->documentIdentifier, $modx->documentObject['alias'], $qs . "page=$pageNum$orderBy$orderDir"): $this->prepareLink($link) . "page=$pageNum"; |
|
466 | - $nav .= '<li'.($currentPage? ' class="currentPage"': '').'><a'.($currentPage? ' class="currentPage"': '').' href="'.$link.'">'.$displayText.'</a></li>'."\n"; |
|
467 | - return $nav; |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * Adds an INPUT form element column to the table. |
|
472 | - * |
|
473 | - * @param $value The value attribute of the element. |
|
474 | - * @param $isChecked Indicates if the checked attribute should apply to the |
|
475 | - * element. |
|
476 | - */ |
|
461 | + global $modx; |
|
462 | + $orderBy= !empty($_GET['orderby'])? '&orderby=' . $_GET['orderby']: ''; |
|
463 | + $orderDir= !empty($_GET['orderdir'])? '&orderdir=' . $_GET['orderdir']: ''; |
|
464 | + if (!empty($qs)) $qs= "?$qs"; |
|
465 | + $link= empty($link)? $modx->makeUrl($modx->documentIdentifier, $modx->documentObject['alias'], $qs . "page=$pageNum$orderBy$orderDir"): $this->prepareLink($link) . "page=$pageNum"; |
|
466 | + $nav .= '<li'.($currentPage? ' class="currentPage"': '').'><a'.($currentPage? ' class="currentPage"': '').' href="'.$link.'">'.$displayText.'</a></li>'."\n"; |
|
467 | + return $nav; |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * Adds an INPUT form element column to the table. |
|
472 | + * |
|
473 | + * @param $value The value attribute of the element. |
|
474 | + * @param $isChecked Indicates if the checked attribute should apply to the |
|
475 | + * element. |
|
476 | + */ |
|
477 | 477 | public function addFormField($value, $isChecked) { |
478 | - if ($this->formElementType) { |
|
479 | - $checked= $isChecked? "checked ": ""; |
|
480 | - $field= "\t\t".'<td><input type="'.$this->formElementType.'" name="'. ($this->formElementName ? $this->formElementName : $value).'" value="'.$value.'" '.$checked.'/></td>'."\n"; |
|
481 | - } |
|
482 | - return $field; |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * Generates the proper LIMIT clause for queries to retrieve paged results in |
|
487 | - * a MakeTable $fieldsArray. |
|
488 | - */ |
|
478 | + if ($this->formElementType) { |
|
479 | + $checked= $isChecked? "checked ": ""; |
|
480 | + $field= "\t\t".'<td><input type="'.$this->formElementType.'" name="'. ($this->formElementName ? $this->formElementName : $value).'" value="'.$value.'" '.$checked.'/></td>'."\n"; |
|
481 | + } |
|
482 | + return $field; |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * Generates the proper LIMIT clause for queries to retrieve paged results in |
|
487 | + * a MakeTable $fieldsArray. |
|
488 | + */ |
|
489 | 489 | public function handlePaging() { |
490 | - $offset= (is_numeric($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] - 1 : 0; |
|
491 | - $limitClause= ' LIMIT '. ($offset * MAX_DISPLAY_RECORDS_NUM).', '.MAX_DISPLAY_RECORDS_NUM; |
|
492 | - return $limitClause; |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * Generates the SORT BY clause for queries used to retrieve a MakeTable |
|
497 | - * $fieldsArray |
|
498 | - * |
|
499 | - * @param $natural_order If true, the results are returned in natural order. |
|
500 | - */ |
|
490 | + $offset= (is_numeric($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] - 1 : 0; |
|
491 | + $limitClause= ' LIMIT '. ($offset * MAX_DISPLAY_RECORDS_NUM).', '.MAX_DISPLAY_RECORDS_NUM; |
|
492 | + return $limitClause; |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * Generates the SORT BY clause for queries used to retrieve a MakeTable |
|
497 | + * $fieldsArray |
|
498 | + * |
|
499 | + * @param $natural_order If true, the results are returned in natural order. |
|
500 | + */ |
|
501 | 501 | public function handleSorting($natural_order=false) { |
502 | - $orderByClause= ''; |
|
503 | - if (!$natural_order) { |
|
504 | - $orderby= !empty($_GET['orderby'])? $_GET['orderby']: "id"; |
|
505 | - $orderdir= !empty($_GET['orderdir'])? $_GET['orderdir']: "DESC"; |
|
506 | - $orderbyClause= !empty($orderby)? ' ORDER BY ' . $orderby . ' ' . $orderdir . ' ': ""; |
|
507 | - } |
|
508 | - return $orderbyClause; |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * Generates a link to order by a specific $fieldsArray key; use to generate |
|
513 | - * sort by links in the MakeTable $fieldHeadingsArray values. |
|
514 | - * |
|
515 | - * @param $key The $fieldsArray key for the column to sort by. |
|
516 | - * @param $text The text for the link (e.g. table column header). |
|
517 | - * @param $qs An optional query string to append to the order by link. |
|
518 | - */ |
|
502 | + $orderByClause= ''; |
|
503 | + if (!$natural_order) { |
|
504 | + $orderby= !empty($_GET['orderby'])? $_GET['orderby']: "id"; |
|
505 | + $orderdir= !empty($_GET['orderdir'])? $_GET['orderdir']: "DESC"; |
|
506 | + $orderbyClause= !empty($orderby)? ' ORDER BY ' . $orderby . ' ' . $orderdir . ' ': ""; |
|
507 | + } |
|
508 | + return $orderbyClause; |
|
509 | + } |
|
510 | + |
|
511 | + /** |
|
512 | + * Generates a link to order by a specific $fieldsArray key; use to generate |
|
513 | + * sort by links in the MakeTable $fieldHeadingsArray values. |
|
514 | + * |
|
515 | + * @param $key The $fieldsArray key for the column to sort by. |
|
516 | + * @param $text The text for the link (e.g. table column header). |
|
517 | + * @param $qs An optional query string to append to the order by link. |
|
518 | + */ |
|
519 | 519 | public function prepareOrderByLink($key, $text, $qs='') { |
520 | - global $modx; |
|
521 | - if (!empty($_GET['orderdir'])) { |
|
522 | - $orderDir= strtolower($_GET['orderdir'])=='desc'? '&orderdir=asc': '&orderdir=desc'; |
|
523 | - } else { |
|
524 | - $orderDir= '&orderdir=asc'; |
|
525 | - } |
|
526 | - if (!empty($qs)) { |
|
527 | - if (!strrpos($qs, '&')==strlen($qs)-1) $qs.= '&'; |
|
528 | - } |
|
529 | - return '<a href="[~'.$modx->documentIdentifier.'~]?'.$qs.'orderby='.$key.$orderDir.'">'.$text.'</a>'; |
|
530 | - } |
|
520 | + global $modx; |
|
521 | + if (!empty($_GET['orderdir'])) { |
|
522 | + $orderDir= strtolower($_GET['orderdir'])=='desc'? '&orderdir=asc': '&orderdir=desc'; |
|
523 | + } else { |
|
524 | + $orderDir= '&orderdir=asc'; |
|
525 | + } |
|
526 | + if (!empty($qs)) { |
|
527 | + if (!strrpos($qs, '&')==strlen($qs)-1) $qs.= '&'; |
|
528 | + } |
|
529 | + return '<a href="[~'.$modx->documentIdentifier.'~]?'.$qs.'orderby='.$key.$orderDir.'">'.$text.'</a>'; |
|
530 | + } |
|
531 | 531 | |
532 | 532 | } |
@@ -30,6 +30,11 @@ discard block |
||
30 | 30 | $this->condModifiers = '=,is,eq,equals,ne,neq,notequals,isnot,isnt,not,%,isempty,isnotempty,isntempty,>=,gte,eg,gte,greaterthan,>,gt,isgreaterthan,isgt,lowerthan,<,lt,<=,lte,islte,islowerthan,islt,el,find,in,inarray,in_array,fnmatch,wcard,wcard_match,wildcard,wildcard_match,is_file,is_dir,file_exists,is_readable,is_writable,is_image,regex,preg,preg_match,memberof,mo,isinrole,ir'; |
31 | 31 | } |
32 | 32 | |
33 | + /** |
|
34 | + * @param string $key |
|
35 | + * @param string $value |
|
36 | + * @param string|false $modifiers |
|
37 | + */ |
|
33 | 38 | public function phxFilter($key,$value,$modifiers) |
34 | 39 | { |
35 | 40 | global $modx; |
@@ -51,6 +56,10 @@ discard block |
||
51 | 56 | return $value; |
52 | 57 | } |
53 | 58 | |
59 | + /** |
|
60 | + * @param string $mode |
|
61 | + * @param string $modifiers |
|
62 | + */ |
|
54 | 63 | public function _getDelim($mode,$modifiers) { |
55 | 64 | $c = substr($modifiers,0,1); |
56 | 65 | if(!in_array($c, array('"', "'", '`')) ) return false; |
@@ -62,6 +71,11 @@ discard block |
||
62 | 71 | return $c; |
63 | 72 | } |
64 | 73 | |
74 | + /** |
|
75 | + * @param string $mode |
|
76 | + * @param false|string $delim |
|
77 | + * @param string $modifiers |
|
78 | + */ |
|
65 | 79 | public function _getOpt($mode,$delim,$modifiers) { |
66 | 80 | if($delim) { |
67 | 81 | if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1); |
@@ -80,6 +94,14 @@ discard block |
||
80 | 94 | return $opt; |
81 | 95 | } |
82 | 96 | } |
97 | + |
|
98 | + /** |
|
99 | + * @param string $mode |
|
100 | + * @param false|string $delim |
|
101 | + * @param string $modifiers |
|
102 | + * |
|
103 | + * @return string |
|
104 | + */ |
|
83 | 105 | public function _getRemainModifiers($mode,$delim,$modifiers) { |
84 | 106 | if($delim) { |
85 | 107 | if($mode=='(') |
@@ -107,6 +129,9 @@ discard block |
||
107 | 129 | return substr($string,strpos($string, $delim)+$len); |
108 | 130 | } |
109 | 131 | |
132 | + /** |
|
133 | + * @param string $modifiers |
|
134 | + */ |
|
110 | 135 | public function splitEachModifiers($modifiers) { |
111 | 136 | global $modx; |
112 | 137 | |
@@ -242,6 +267,9 @@ discard block |
||
242 | 267 | else return true; |
243 | 268 | } |
244 | 269 | |
270 | + /** |
|
271 | + * @param string $cmd |
|
272 | + */ |
|
245 | 273 | public function getValueFromPreset($key, $value, $cmd, $opt) |
246 | 274 | { |
247 | 275 | global $modx; |
@@ -927,6 +955,9 @@ discard block |
||
927 | 955 | return $value; |
928 | 956 | } |
929 | 957 | |
958 | + /** |
|
959 | + * @param string $cmd |
|
960 | + */ |
|
930 | 961 | public function includeMdfFile($cmd) { |
931 | 962 | global $modx; |
932 | 963 | $key = $this->key; |
@@ -1082,6 +1113,10 @@ discard block |
||
1082 | 1113 | } |
1083 | 1114 | |
1084 | 1115 | // Sets a placeholder variable which can only be access by Modifiers |
1116 | + |
|
1117 | + /** |
|
1118 | + * @param string $value |
|
1119 | + */ |
|
1085 | 1120 | public function setModifiersVariable($key, $value) { |
1086 | 1121 | if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value; |
1087 | 1122 | } |
@@ -41,6 +41,10 @@ |
||
41 | 41 | $this->menu = $new; |
42 | 42 | } |
43 | 43 | |
44 | + /** |
|
45 | + * @param string $parentid |
|
46 | + * @param integer $level |
|
47 | + */ |
|
44 | 48 | public function DrawSub($parentid, $level) |
45 | 49 | { |
46 | 50 | global $modx; |
@@ -19,11 +19,17 @@ discard block |
||
19 | 19 | $this->request_time = $_SERVER['REQUEST_TIME'] + $modx->config['server_offset_time']; |
20 | 20 | } |
21 | 21 | |
22 | + /** |
|
23 | + * @param string $path |
|
24 | + */ |
|
22 | 25 | public function setCachepath($path) |
23 | 26 | { |
24 | 27 | $this->cachePath = $path; |
25 | 28 | } |
26 | 29 | |
30 | + /** |
|
31 | + * @param boolean $bool |
|
32 | + */ |
|
27 | 33 | public function setReport($bool) |
28 | 34 | { |
29 | 35 | $this->showReport = $bool; |
@@ -46,6 +52,9 @@ discard block |
||
46 | 52 | return str_replace($q1, $q2, $s); |
47 | 53 | } |
48 | 54 | |
55 | + /** |
|
56 | + * @return string |
|
57 | + */ |
|
49 | 58 | public function getParents($id, $path = '') |
50 | 59 | { // modx:returns child's parent |
51 | 60 | global $modx; |
@@ -149,6 +158,9 @@ discard block |
||
149 | 158 | } |
150 | 159 | } |
151 | 160 | |
161 | + /** |
|
162 | + * @return string |
|
163 | + */ |
|
152 | 164 | public function getCacheRefreshTime() |
153 | 165 | { |
154 | 166 | global $modx; |
@@ -191,7 +203,7 @@ discard block |
||
191 | 203 | /** |
192 | 204 | * build siteCache file |
193 | 205 | * @param DocumentParser $modx |
194 | - * @return boolean success |
|
206 | + * @return null|boolean success |
|
195 | 207 | */ |
196 | 208 | public function buildCache($modx) |
197 | 209 | { |
@@ -1,17 +1,17 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if( ! defined('IN_MANAGER_MODE') || IN_MANAGER_MODE !== true) { |
3 | - die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly."); |
|
3 | + die("<b>INCLUDE_ORDERING_ERROR</b><br /><br />Please use the EVO Content Manager instead of accessing this file directly."); |
|
4 | 4 | } |
5 | 5 | if(!$modx->hasPermission('import_static')) { |
6 | - $modx->webAlertAndQuit($_lang["error_no_privileges"]); |
|
6 | + $modx->webAlertAndQuit($_lang["error_no_privileges"]); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | // Files to upload |
10 | 10 | $allowedfiles = array( |
11 | - 'html', |
|
12 | - 'htm', |
|
13 | - 'shtml', |
|
14 | - 'xml' |
|
11 | + 'html', |
|
12 | + 'htm', |
|
13 | + 'shtml', |
|
14 | + 'xml' |
|
15 | 15 | ); |
16 | 16 | ?> |
17 | 17 | <script language="javascript"> |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | <div class="tab-page"> |
44 | 44 | <div class="container container-body"> |
45 | 45 | <?php |
46 | - if(!isset($_POST['import'])) { |
|
47 | - echo "<div class=\"element-edit-message\">" . $_lang['import_site_message'] . "</div>"; |
|
48 | - ?> |
|
46 | + if(!isset($_POST['import'])) { |
|
47 | + echo "<div class=\"element-edit-message\">" . $_lang['import_site_message'] . "</div>"; |
|
48 | + ?> |
|
49 | 49 | <form action="index.php" method="post" name="importFrm"> |
50 | 50 | <input type="hidden" name="import" value="import" /> |
51 | 51 | <input type="hidden" name="a" value="95" /> |
@@ -85,375 +85,375 @@ discard block |
||
85 | 85 | <a href="javascript:;" class="btn btn-primary" onclick="window.importFrm.submit();"><i class="<?= $_style["actions_save"] ?>"></i> <?= $_lang["import_site_start"] ?></a> |
86 | 86 | </form> |
87 | 87 | <?php |
88 | - } else { |
|
89 | - run(); |
|
90 | - $modx->clearCache('full'); |
|
91 | - ?> |
|
88 | + } else { |
|
89 | + run(); |
|
90 | + $modx->clearCache('full'); |
|
91 | + ?> |
|
92 | 92 | <a href="javascript:;" class="btn btn-primary" onclick="window.location.href='index.php?a=2';"><i class="<?= $_style["actions_close"] ?>"></i> <?= $_lang["close"] ?></a> |
93 | 93 | <script type="text/javascript"> |
94 | 94 | top.mainMenu.reloadtree(); |
95 | 95 | parent.tree.ca = 'open'; |
96 | 96 | </script> |
97 | 97 | <?php |
98 | - } |
|
99 | - ?> |
|
98 | + } |
|
99 | + ?> |
|
100 | 100 | </div> |
101 | 101 | </div> |
102 | 102 | |
103 | 103 | <?php |
104 | 104 | function run() { |
105 | - global $modx, $_lang; |
|
105 | + global $modx, $_lang; |
|
106 | 106 | |
107 | - $tbl_site_content = $modx->getFullTableName('site_content'); |
|
108 | - $output = ''; |
|
109 | - $maxtime = $_POST['maxtime']; |
|
107 | + $tbl_site_content = $modx->getFullTableName('site_content'); |
|
108 | + $output = ''; |
|
109 | + $maxtime = $_POST['maxtime']; |
|
110 | 110 | |
111 | - if(!is_numeric($maxtime)) { |
|
112 | - $maxtime = 30; |
|
113 | - } |
|
111 | + if(!is_numeric($maxtime)) { |
|
112 | + $maxtime = 30; |
|
113 | + } |
|
114 | 114 | |
115 | - @set_time_limit($maxtime); |
|
115 | + @set_time_limit($maxtime); |
|
116 | 116 | |
117 | - $mtime = microtime(); |
|
118 | - $mtime = explode(' ', $mtime); |
|
119 | - $mtime = $mtime[1] + $mtime[0]; |
|
120 | - $importstart = $mtime; |
|
117 | + $mtime = microtime(); |
|
118 | + $mtime = explode(' ', $mtime); |
|
119 | + $mtime = $mtime[1] + $mtime[0]; |
|
120 | + $importstart = $mtime; |
|
121 | 121 | |
122 | - if($_POST['reset'] == 'on') { |
|
123 | - $modx->db->truncate($tbl_site_content); |
|
124 | - $modx->db->query("ALTER TABLE {$tbl_site_content} AUTO_INCREMENT = 1"); |
|
125 | - } |
|
122 | + if($_POST['reset'] == 'on') { |
|
123 | + $modx->db->truncate($tbl_site_content); |
|
124 | + $modx->db->query("ALTER TABLE {$tbl_site_content} AUTO_INCREMENT = 1"); |
|
125 | + } |
|
126 | 126 | |
127 | - $parent = (int)$_POST['parent']; |
|
127 | + $parent = (int)$_POST['parent']; |
|
128 | 128 | |
129 | - if(is_dir(MODX_BASE_PATH . 'temp/import')) { |
|
130 | - $filedir = MODX_BASE_PATH . 'temp/import/'; |
|
131 | - } elseif(is_dir(MODX_BASE_PATH . 'assets/import')) { |
|
132 | - $filedir = MODX_BASE_PATH . 'assets/import/'; |
|
133 | - } else { |
|
129 | + if(is_dir(MODX_BASE_PATH . 'temp/import')) { |
|
130 | + $filedir = MODX_BASE_PATH . 'temp/import/'; |
|
131 | + } elseif(is_dir(MODX_BASE_PATH . 'assets/import')) { |
|
132 | + $filedir = MODX_BASE_PATH . 'assets/import/'; |
|
133 | + } else { |
|
134 | 134 | $filedir = ''; |
135 | 135 | } |
136 | 136 | |
137 | - $filesfound = 0; |
|
137 | + $filesfound = 0; |
|
138 | 138 | |
139 | - $files = getFiles($filedir); |
|
140 | - $files = pop_index($files); |
|
139 | + $files = getFiles($filedir); |
|
140 | + $files = pop_index($files); |
|
141 | 141 | |
142 | - // no. of files to import |
|
143 | - $output .= sprintf('<p>' . $_lang['import_files_found'] . '</p>', $filesfound); |
|
142 | + // no. of files to import |
|
143 | + $output .= sprintf('<p>' . $_lang['import_files_found'] . '</p>', $filesfound); |
|
144 | 144 | |
145 | - // import files |
|
146 | - if(0 < count($files)) { |
|
147 | - $modx->db->update(array('isfolder' => 1), $tbl_site_content, "id='{$parent}'"); |
|
148 | - importFiles($parent, $filedir, $files, 'root'); |
|
149 | - } |
|
145 | + // import files |
|
146 | + if(0 < count($files)) { |
|
147 | + $modx->db->update(array('isfolder' => 1), $tbl_site_content, "id='{$parent}'"); |
|
148 | + importFiles($parent, $filedir, $files, 'root'); |
|
149 | + } |
|
150 | 150 | |
151 | - $mtime = microtime(); |
|
152 | - $mtime = explode(' ', $mtime); |
|
153 | - $mtime = $mtime[1] + $mtime[0]; |
|
154 | - $importend = $mtime; |
|
155 | - $totaltime = ($importend - $importstart); |
|
156 | - $output .= sprintf('<p>' . $_lang['import_site_time'] . '</p>', round($totaltime, 3)); |
|
151 | + $mtime = microtime(); |
|
152 | + $mtime = explode(' ', $mtime); |
|
153 | + $mtime = $mtime[1] + $mtime[0]; |
|
154 | + $importend = $mtime; |
|
155 | + $totaltime = ($importend - $importstart); |
|
156 | + $output .= sprintf('<p>' . $_lang['import_site_time'] . '</p>', round($totaltime, 3)); |
|
157 | 157 | |
158 | - if($_POST['convert_link'] == 'on') { |
|
159 | - convertLink(); |
|
160 | - } |
|
158 | + if($_POST['convert_link'] == 'on') { |
|
159 | + convertLink(); |
|
160 | + } |
|
161 | 161 | |
162 | - return $output; |
|
162 | + return $output; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | function importFiles($parent, $filedir, $files, $mode) { |
166 | - global $modx; |
|
167 | - global $_lang, $allowedfiles; |
|
168 | - global $search_default, $cache_default, $publish_default; |
|
169 | - |
|
170 | - $tbl_site_content = $modx->getFullTableName('site_content'); |
|
171 | - $tbl_system_settings = $modx->getFullTableName('system_settings'); |
|
172 | - |
|
173 | - $createdby = $modx->getLoginUserID(); |
|
174 | - if(!is_array($files)) { |
|
175 | - return; |
|
176 | - } |
|
177 | - if($_POST['object'] == 'all') { |
|
178 | - $modx->config['default_template'] = '0'; |
|
179 | - $richtext = '0'; |
|
180 | - } else { |
|
181 | - $richtext = '1'; |
|
182 | - } |
|
183 | - |
|
184 | - foreach($files as $id => $value) { |
|
185 | - if(is_array($value)) { |
|
186 | - // create folder |
|
187 | - $alias = $id; |
|
188 | - printf('<span>' . $_lang['import_site_importing_document'] . '</span>', $alias); |
|
189 | - $field = array(); |
|
190 | - $field['type'] = 'document'; |
|
191 | - $field['contentType'] = 'text/html'; |
|
192 | - $field['published'] = $publish_default; |
|
193 | - $field['parent'] = $parent; |
|
194 | - $field['alias'] = $modx->stripAlias($alias); |
|
195 | - $field['richtext'] = $richtext; |
|
196 | - $field['template'] = $modx->config['default_template']; |
|
197 | - $field['searchable'] = $search_default; |
|
198 | - $field['cacheable'] = $cache_default; |
|
199 | - $field['createdby'] = $createdby; |
|
200 | - $field['isfolder'] = 1; |
|
201 | - $field['menuindex'] = 1; |
|
202 | - $find = false; |
|
203 | - foreach(array( |
|
204 | - 'index.html', |
|
205 | - 'index.htm' |
|
206 | - ) as $filename) { |
|
207 | - $filepath = $filedir . $alias . '/' . $filename; |
|
208 | - if($find === false && file_exists($filepath)) { |
|
209 | - $file = getFileContent($filepath); |
|
210 | - list($pagetitle, $content, $description) = treatContent($file, $filename, $alias); |
|
211 | - |
|
212 | - $date = filemtime($filepath); |
|
213 | - $field['pagetitle'] = $pagetitle; |
|
214 | - $field['longtitle'] = $pagetitle; |
|
215 | - $field['description'] = $description; |
|
216 | - $field['content'] = $modx->db->escape($content); |
|
217 | - $field['createdon'] = $date; |
|
218 | - $field['editedon'] = $date; |
|
219 | - $newid = $modx->db->insert($field, $tbl_site_content); |
|
220 | - if($newid) { |
|
221 | - $find = true; |
|
222 | - echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n"; |
|
223 | - importFiles($newid, $filedir . $alias . '/', $value, 'sub'); |
|
224 | - } else { |
|
225 | - echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError(); |
|
226 | - exit; |
|
227 | - } |
|
228 | - } |
|
229 | - } |
|
230 | - if($find === false) { |
|
231 | - $date = time(); |
|
232 | - $field['pagetitle'] = '---'; |
|
233 | - $field['content'] = ''; |
|
234 | - $field['createdon'] = $date; |
|
235 | - $field['editedon'] = $date; |
|
236 | - $field['hidemenu'] = '1'; |
|
237 | - $newid = $modx->db->insert($field, $tbl_site_content); |
|
238 | - if($newid) { |
|
239 | - $find = true; |
|
240 | - echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n"; |
|
241 | - importFiles($newid, $filedir . $alias . '/', $value, 'sub'); |
|
242 | - } else { |
|
243 | - echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError(); |
|
244 | - exit; |
|
245 | - } |
|
246 | - } |
|
247 | - } else { |
|
248 | - // create document |
|
249 | - if($mode == 'sub' && $value == 'index.html') { |
|
250 | - continue; |
|
251 | - } |
|
252 | - $filename = $value; |
|
253 | - $fparts = explode('.', $value); |
|
254 | - $alias = $fparts[0]; |
|
255 | - $ext = (count($fparts) > 1) ? $fparts[count($fparts) - 1] : ""; |
|
256 | - printf("<span>" . $_lang['import_site_importing_document'] . "</span>", $filename); |
|
257 | - |
|
258 | - if(!in_array($ext, $allowedfiles)) { |
|
259 | - echo ' - <span class="fail">' . $_lang["import_site_skip"] . '</span><br />' . "\n"; |
|
260 | - } else { |
|
261 | - $filepath = $filedir . $filename; |
|
262 | - $file = getFileContent($filepath); |
|
263 | - list($pagetitle, $content, $description) = treatContent($file, $filename, $alias); |
|
264 | - |
|
265 | - $date = filemtime($filepath); |
|
266 | - $field = array(); |
|
267 | - $field['type'] = 'document'; |
|
268 | - $field['contentType'] = 'text/html'; |
|
269 | - $field['pagetitle'] = $pagetitle; |
|
270 | - $field['longtitle'] = $pagetitle; |
|
271 | - $field['description'] = $description; |
|
272 | - $field['alias'] = $modx->stripAlias($alias); |
|
273 | - $field['published'] = $publish_default; |
|
274 | - $field['parent'] = $parent; |
|
275 | - $field['content'] = $modx->db->escape($content); |
|
276 | - $field['richtext'] = $richtext; |
|
277 | - $field['template'] = $modx->config['default_template']; |
|
278 | - $field['searchable'] = $search_default; |
|
279 | - $field['cacheable'] = $cache_default; |
|
280 | - $field['createdby'] = $createdby; |
|
281 | - $field['createdon'] = $date; |
|
282 | - $field['editedon'] = $date; |
|
283 | - $field['isfolder'] = 0; |
|
284 | - $field['menuindex'] = ($alias == 'index') ? 0 : 2; |
|
285 | - $newid = $modx->db->insert($field, $tbl_site_content); |
|
286 | - if($newid) { |
|
287 | - echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n"; |
|
288 | - } else { |
|
289 | - echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError(); |
|
290 | - exit; |
|
291 | - } |
|
292 | - |
|
293 | - $is_site_start = false; |
|
294 | - if($filename == 'index.html') { |
|
295 | - $is_site_start = true; |
|
296 | - } |
|
297 | - if($is_site_start == true && $_POST['reset'] == 'on') { |
|
298 | - $modx->db->update(array('setting_value' => $newid), $tbl_system_settings, "setting_name='site_start'"); |
|
299 | - $modx->db->update(array('menuindex' => 0), $tbl_site_content, "id='{$newid}'"); |
|
300 | - } |
|
301 | - } |
|
302 | - } |
|
303 | - } |
|
166 | + global $modx; |
|
167 | + global $_lang, $allowedfiles; |
|
168 | + global $search_default, $cache_default, $publish_default; |
|
169 | + |
|
170 | + $tbl_site_content = $modx->getFullTableName('site_content'); |
|
171 | + $tbl_system_settings = $modx->getFullTableName('system_settings'); |
|
172 | + |
|
173 | + $createdby = $modx->getLoginUserID(); |
|
174 | + if(!is_array($files)) { |
|
175 | + return; |
|
176 | + } |
|
177 | + if($_POST['object'] == 'all') { |
|
178 | + $modx->config['default_template'] = '0'; |
|
179 | + $richtext = '0'; |
|
180 | + } else { |
|
181 | + $richtext = '1'; |
|
182 | + } |
|
183 | + |
|
184 | + foreach($files as $id => $value) { |
|
185 | + if(is_array($value)) { |
|
186 | + // create folder |
|
187 | + $alias = $id; |
|
188 | + printf('<span>' . $_lang['import_site_importing_document'] . '</span>', $alias); |
|
189 | + $field = array(); |
|
190 | + $field['type'] = 'document'; |
|
191 | + $field['contentType'] = 'text/html'; |
|
192 | + $field['published'] = $publish_default; |
|
193 | + $field['parent'] = $parent; |
|
194 | + $field['alias'] = $modx->stripAlias($alias); |
|
195 | + $field['richtext'] = $richtext; |
|
196 | + $field['template'] = $modx->config['default_template']; |
|
197 | + $field['searchable'] = $search_default; |
|
198 | + $field['cacheable'] = $cache_default; |
|
199 | + $field['createdby'] = $createdby; |
|
200 | + $field['isfolder'] = 1; |
|
201 | + $field['menuindex'] = 1; |
|
202 | + $find = false; |
|
203 | + foreach(array( |
|
204 | + 'index.html', |
|
205 | + 'index.htm' |
|
206 | + ) as $filename) { |
|
207 | + $filepath = $filedir . $alias . '/' . $filename; |
|
208 | + if($find === false && file_exists($filepath)) { |
|
209 | + $file = getFileContent($filepath); |
|
210 | + list($pagetitle, $content, $description) = treatContent($file, $filename, $alias); |
|
211 | + |
|
212 | + $date = filemtime($filepath); |
|
213 | + $field['pagetitle'] = $pagetitle; |
|
214 | + $field['longtitle'] = $pagetitle; |
|
215 | + $field['description'] = $description; |
|
216 | + $field['content'] = $modx->db->escape($content); |
|
217 | + $field['createdon'] = $date; |
|
218 | + $field['editedon'] = $date; |
|
219 | + $newid = $modx->db->insert($field, $tbl_site_content); |
|
220 | + if($newid) { |
|
221 | + $find = true; |
|
222 | + echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n"; |
|
223 | + importFiles($newid, $filedir . $alias . '/', $value, 'sub'); |
|
224 | + } else { |
|
225 | + echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError(); |
|
226 | + exit; |
|
227 | + } |
|
228 | + } |
|
229 | + } |
|
230 | + if($find === false) { |
|
231 | + $date = time(); |
|
232 | + $field['pagetitle'] = '---'; |
|
233 | + $field['content'] = ''; |
|
234 | + $field['createdon'] = $date; |
|
235 | + $field['editedon'] = $date; |
|
236 | + $field['hidemenu'] = '1'; |
|
237 | + $newid = $modx->db->insert($field, $tbl_site_content); |
|
238 | + if($newid) { |
|
239 | + $find = true; |
|
240 | + echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n"; |
|
241 | + importFiles($newid, $filedir . $alias . '/', $value, 'sub'); |
|
242 | + } else { |
|
243 | + echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError(); |
|
244 | + exit; |
|
245 | + } |
|
246 | + } |
|
247 | + } else { |
|
248 | + // create document |
|
249 | + if($mode == 'sub' && $value == 'index.html') { |
|
250 | + continue; |
|
251 | + } |
|
252 | + $filename = $value; |
|
253 | + $fparts = explode('.', $value); |
|
254 | + $alias = $fparts[0]; |
|
255 | + $ext = (count($fparts) > 1) ? $fparts[count($fparts) - 1] : ""; |
|
256 | + printf("<span>" . $_lang['import_site_importing_document'] . "</span>", $filename); |
|
257 | + |
|
258 | + if(!in_array($ext, $allowedfiles)) { |
|
259 | + echo ' - <span class="fail">' . $_lang["import_site_skip"] . '</span><br />' . "\n"; |
|
260 | + } else { |
|
261 | + $filepath = $filedir . $filename; |
|
262 | + $file = getFileContent($filepath); |
|
263 | + list($pagetitle, $content, $description) = treatContent($file, $filename, $alias); |
|
264 | + |
|
265 | + $date = filemtime($filepath); |
|
266 | + $field = array(); |
|
267 | + $field['type'] = 'document'; |
|
268 | + $field['contentType'] = 'text/html'; |
|
269 | + $field['pagetitle'] = $pagetitle; |
|
270 | + $field['longtitle'] = $pagetitle; |
|
271 | + $field['description'] = $description; |
|
272 | + $field['alias'] = $modx->stripAlias($alias); |
|
273 | + $field['published'] = $publish_default; |
|
274 | + $field['parent'] = $parent; |
|
275 | + $field['content'] = $modx->db->escape($content); |
|
276 | + $field['richtext'] = $richtext; |
|
277 | + $field['template'] = $modx->config['default_template']; |
|
278 | + $field['searchable'] = $search_default; |
|
279 | + $field['cacheable'] = $cache_default; |
|
280 | + $field['createdby'] = $createdby; |
|
281 | + $field['createdon'] = $date; |
|
282 | + $field['editedon'] = $date; |
|
283 | + $field['isfolder'] = 0; |
|
284 | + $field['menuindex'] = ($alias == 'index') ? 0 : 2; |
|
285 | + $newid = $modx->db->insert($field, $tbl_site_content); |
|
286 | + if($newid) { |
|
287 | + echo ' - <span class="success">' . $_lang['import_site_success'] . '</span><br />' . "\n"; |
|
288 | + } else { |
|
289 | + echo '<span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_db_error"] . $modx->db->getLastError(); |
|
290 | + exit; |
|
291 | + } |
|
292 | + |
|
293 | + $is_site_start = false; |
|
294 | + if($filename == 'index.html') { |
|
295 | + $is_site_start = true; |
|
296 | + } |
|
297 | + if($is_site_start == true && $_POST['reset'] == 'on') { |
|
298 | + $modx->db->update(array('setting_value' => $newid), $tbl_system_settings, "setting_name='site_start'"); |
|
299 | + $modx->db->update(array('menuindex' => 0), $tbl_site_content, "id='{$newid}'"); |
|
300 | + } |
|
301 | + } |
|
302 | + } |
|
303 | + } |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | function getFiles($directory, $listing = array(), $count = 0) { |
307 | - global $_lang; |
|
308 | - global $filesfound; |
|
309 | - $dummy = $count; |
|
310 | - if( ! empty($directory) && $files = scandir($directory)) { |
|
311 | - foreach($files as $file) { |
|
312 | - if($file == '.' || $file == '..') { |
|
313 | - continue; |
|
314 | - } elseif($h = @opendir($directory . $file . "/")) { |
|
315 | - closedir($h); |
|
316 | - $count = -1; |
|
317 | - $listing[$file] = getFiles($directory . $file . "/", array(), $count + 1); |
|
318 | - } elseif(strpos($file, '.htm') !== false) { |
|
319 | - $listing[$dummy] = $file; |
|
320 | - $dummy = $dummy + 1; |
|
321 | - $filesfound++; |
|
322 | - } |
|
323 | - } |
|
324 | - } else { |
|
325 | - echo '<p><span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_no_open_dir"] . $directory . ".</p>"; |
|
326 | - } |
|
327 | - return ($listing); |
|
307 | + global $_lang; |
|
308 | + global $filesfound; |
|
309 | + $dummy = $count; |
|
310 | + if( ! empty($directory) && $files = scandir($directory)) { |
|
311 | + foreach($files as $file) { |
|
312 | + if($file == '.' || $file == '..') { |
|
313 | + continue; |
|
314 | + } elseif($h = @opendir($directory . $file . "/")) { |
|
315 | + closedir($h); |
|
316 | + $count = -1; |
|
317 | + $listing[$file] = getFiles($directory . $file . "/", array(), $count + 1); |
|
318 | + } elseif(strpos($file, '.htm') !== false) { |
|
319 | + $listing[$dummy] = $file; |
|
320 | + $dummy = $dummy + 1; |
|
321 | + $filesfound++; |
|
322 | + } |
|
323 | + } |
|
324 | + } else { |
|
325 | + echo '<p><span class="fail">' . $_lang["import_site_failed"] . "</span> " . $_lang["import_site_failed_no_open_dir"] . $directory . ".</p>"; |
|
326 | + } |
|
327 | + return ($listing); |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | function getFileContent($filepath) { |
331 | - global $_lang; |
|
332 | - // get the file |
|
333 | - if(!$buffer = file_get_contents($filepath)) { |
|
334 | - echo '<p><span class="fail">' . $_lang['import_site_failed'] . "</span> " . $_lang["import_site_failed_no_retrieve_file"] . $filepath . ".</p>"; |
|
335 | - } else { |
|
336 | - return $buffer; |
|
337 | - } |
|
331 | + global $_lang; |
|
332 | + // get the file |
|
333 | + if(!$buffer = file_get_contents($filepath)) { |
|
334 | + echo '<p><span class="fail">' . $_lang['import_site_failed'] . "</span> " . $_lang["import_site_failed_no_retrieve_file"] . $filepath . ".</p>"; |
|
335 | + } else { |
|
336 | + return $buffer; |
|
337 | + } |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | function pop_index($array) { |
341 | - $new_array = array(); |
|
342 | - foreach($array as $k => $v) { |
|
343 | - if($v !== 'index.html' && $v !== 'index.htm') { |
|
344 | - $new_array[$k] = $v; |
|
345 | - } else { |
|
346 | - array_unshift($new_array, $v); |
|
347 | - } |
|
348 | - } |
|
349 | - foreach($array as $k => $v) { |
|
350 | - if(is_array($v)) { |
|
351 | - $new_array[$k] = $v; |
|
352 | - } |
|
353 | - } |
|
354 | - return $new_array; |
|
341 | + $new_array = array(); |
|
342 | + foreach($array as $k => $v) { |
|
343 | + if($v !== 'index.html' && $v !== 'index.htm') { |
|
344 | + $new_array[$k] = $v; |
|
345 | + } else { |
|
346 | + array_unshift($new_array, $v); |
|
347 | + } |
|
348 | + } |
|
349 | + foreach($array as $k => $v) { |
|
350 | + if(is_array($v)) { |
|
351 | + $new_array[$k] = $v; |
|
352 | + } |
|
353 | + } |
|
354 | + return $new_array; |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | function treatContent($src, $filename, $alias) { |
358 | - global $modx; |
|
359 | - |
|
360 | - $src = mb_convert_encoding($src, $modx->config['modx_charset'], 'UTF-8,SJIS-win,eucJP-win,SJIS,EUC-JP,ASCII'); |
|
361 | - |
|
362 | - if(preg_match("@<title>(.*)</title>@i", $src, $matches)) { |
|
363 | - $pagetitle = ($matches[1] !== '') ? $matches[1] : $filename; |
|
364 | - $pagetitle = str_replace('[*pagetitle*]', '', $pagetitle); |
|
365 | - } else { |
|
366 | - $pagetitle = $alias; |
|
367 | - } |
|
368 | - if(!$pagetitle) { |
|
369 | - $pagetitle = $alias; |
|
370 | - } |
|
371 | - |
|
372 | - if(preg_match('@<meta[^>]+"description"[^>]+content=[\'"](.*)[\'"].+>@i', $src, $matches)) { |
|
373 | - $description = ($matches[1] !== '') ? $matches[1] : $filename; |
|
374 | - $description = str_replace('[*description*]', '', $description); |
|
375 | - } else { |
|
376 | - $description = ''; |
|
377 | - } |
|
378 | - |
|
379 | - if((preg_match("@<body[^>]*>(.*)[^<]+</body>@is", $src, $matches)) && $_POST['object'] == 'body') { |
|
380 | - $content = $matches[1]; |
|
381 | - } else { |
|
382 | - $content = $src; |
|
383 | - $s = '/(<meta[^>]+charset\s*=)[^>"\'=]+(.+>)/i'; |
|
384 | - $r = '$1' . $modx->config['modx_charset'] . '$2'; |
|
385 | - $content = preg_replace($s, $r, $content); |
|
386 | - $content = preg_replace('@<title>.*</title>@i', "<title>[*pagetitle*]</title>", $content); |
|
387 | - } |
|
388 | - $content = str_replace('[*content*]', '[ *content* ]', $content); |
|
389 | - $content = trim($content); |
|
390 | - $pagetitle = $modx->db->escape($pagetitle); |
|
391 | - return array( |
|
392 | - $pagetitle, |
|
393 | - $content, |
|
394 | - $description |
|
395 | - ); |
|
358 | + global $modx; |
|
359 | + |
|
360 | + $src = mb_convert_encoding($src, $modx->config['modx_charset'], 'UTF-8,SJIS-win,eucJP-win,SJIS,EUC-JP,ASCII'); |
|
361 | + |
|
362 | + if(preg_match("@<title>(.*)</title>@i", $src, $matches)) { |
|
363 | + $pagetitle = ($matches[1] !== '') ? $matches[1] : $filename; |
|
364 | + $pagetitle = str_replace('[*pagetitle*]', '', $pagetitle); |
|
365 | + } else { |
|
366 | + $pagetitle = $alias; |
|
367 | + } |
|
368 | + if(!$pagetitle) { |
|
369 | + $pagetitle = $alias; |
|
370 | + } |
|
371 | + |
|
372 | + if(preg_match('@<meta[^>]+"description"[^>]+content=[\'"](.*)[\'"].+>@i', $src, $matches)) { |
|
373 | + $description = ($matches[1] !== '') ? $matches[1] : $filename; |
|
374 | + $description = str_replace('[*description*]', '', $description); |
|
375 | + } else { |
|
376 | + $description = ''; |
|
377 | + } |
|
378 | + |
|
379 | + if((preg_match("@<body[^>]*>(.*)[^<]+</body>@is", $src, $matches)) && $_POST['object'] == 'body') { |
|
380 | + $content = $matches[1]; |
|
381 | + } else { |
|
382 | + $content = $src; |
|
383 | + $s = '/(<meta[^>]+charset\s*=)[^>"\'=]+(.+>)/i'; |
|
384 | + $r = '$1' . $modx->config['modx_charset'] . '$2'; |
|
385 | + $content = preg_replace($s, $r, $content); |
|
386 | + $content = preg_replace('@<title>.*</title>@i', "<title>[*pagetitle*]</title>", $content); |
|
387 | + } |
|
388 | + $content = str_replace('[*content*]', '[ *content* ]', $content); |
|
389 | + $content = trim($content); |
|
390 | + $pagetitle = $modx->db->escape($pagetitle); |
|
391 | + return array( |
|
392 | + $pagetitle, |
|
393 | + $content, |
|
394 | + $description |
|
395 | + ); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | function convertLink() { |
399 | - global $modx; |
|
400 | - $tbl_site_content = $modx->getFullTableName('site_content'); |
|
399 | + global $modx; |
|
400 | + $tbl_site_content = $modx->getFullTableName('site_content'); |
|
401 | 401 | |
402 | - $rs = $modx->db->select('id,content', $tbl_site_content); |
|
403 | - $p = array(); |
|
402 | + $rs = $modx->db->select('id,content', $tbl_site_content); |
|
403 | + $p = array(); |
|
404 | 404 | $target = array(); |
405 | - $dir = ''; |
|
406 | - while($row = $modx->db->getRow($rs)) { |
|
407 | - $id = $row['id']; |
|
408 | - $array = explode('<a href=', $row['content']); |
|
409 | - $c = 0; |
|
410 | - foreach($array as $v) { |
|
411 | - if($v[0] === '"') { |
|
412 | - $v = substr($v, 1); |
|
413 | - list($href, $v) = explode('"', $v, 2); |
|
414 | - $_ = $href; |
|
415 | - if(strpos($_, $modx->config['site_url']) !== false) { |
|
416 | - $_ = $modx->config['base_url'] . str_replace($modx->config['site_url'], '', $_); |
|
417 | - } |
|
418 | - if($_[0] === '/') { |
|
419 | - $_ = substr($_, 1); |
|
420 | - } |
|
421 | - $_ = str_replace('/index.html', '.html', $_); |
|
422 | - $level = substr_count($_, '../'); |
|
423 | - if(1 < $level) { |
|
424 | - if(!isset($p[$id])) { |
|
425 | - $p[$id] = $modx->getParentIds($id); |
|
426 | - } |
|
427 | - $k = array_keys($p[$id]); |
|
428 | - while(0 < $level) { |
|
429 | - $dir = array_shift($k); |
|
430 | - $level--; |
|
431 | - } |
|
432 | - if($dir != '') { |
|
433 | - $dir .= '/'; |
|
434 | - } |
|
435 | - } else { |
|
436 | - $dir = ''; |
|
437 | - } |
|
438 | - |
|
439 | - $_ = trim($_, './'); |
|
440 | - if(strpos($_, '/') !== false) { |
|
441 | - $_ = substr($_, strrpos($_, '/')); |
|
442 | - } |
|
443 | - $_ = $dir . str_replace('.html', '', $_); |
|
444 | - if(!isset($target[$_])) { |
|
445 | - $target[$_] = $modx->getIdFromAlias($_); |
|
446 | - } |
|
447 | - $target[$_] = trim($target[$_]); |
|
448 | - if(!empty($target[$_])) { |
|
449 | - $href = '[~' . $target[$_] . '~]'; |
|
450 | - } |
|
451 | - $array[$c] = '<a href="' . $href . '"' . $v; |
|
452 | - } |
|
453 | - $c++; |
|
454 | - } |
|
455 | - $content = implode('', $array); |
|
456 | - $f['content'] = $modx->db->escape($content); |
|
457 | - $modx->db->update($f, $tbl_site_content, "id='{$id}'"); |
|
458 | - } |
|
405 | + $dir = ''; |
|
406 | + while($row = $modx->db->getRow($rs)) { |
|
407 | + $id = $row['id']; |
|
408 | + $array = explode('<a href=', $row['content']); |
|
409 | + $c = 0; |
|
410 | + foreach($array as $v) { |
|
411 | + if($v[0] === '"') { |
|
412 | + $v = substr($v, 1); |
|
413 | + list($href, $v) = explode('"', $v, 2); |
|
414 | + $_ = $href; |
|
415 | + if(strpos($_, $modx->config['site_url']) !== false) { |
|
416 | + $_ = $modx->config['base_url'] . str_replace($modx->config['site_url'], '', $_); |
|
417 | + } |
|
418 | + if($_[0] === '/') { |
|
419 | + $_ = substr($_, 1); |
|
420 | + } |
|
421 | + $_ = str_replace('/index.html', '.html', $_); |
|
422 | + $level = substr_count($_, '../'); |
|
423 | + if(1 < $level) { |
|
424 | + if(!isset($p[$id])) { |
|
425 | + $p[$id] = $modx->getParentIds($id); |
|
426 | + } |
|
427 | + $k = array_keys($p[$id]); |
|
428 | + while(0 < $level) { |
|
429 | + $dir = array_shift($k); |
|
430 | + $level--; |
|
431 | + } |
|
432 | + if($dir != '') { |
|
433 | + $dir .= '/'; |
|
434 | + } |
|
435 | + } else { |
|
436 | + $dir = ''; |
|
437 | + } |
|
438 | + |
|
439 | + $_ = trim($_, './'); |
|
440 | + if(strpos($_, '/') !== false) { |
|
441 | + $_ = substr($_, strrpos($_, '/')); |
|
442 | + } |
|
443 | + $_ = $dir . str_replace('.html', '', $_); |
|
444 | + if(!isset($target[$_])) { |
|
445 | + $target[$_] = $modx->getIdFromAlias($_); |
|
446 | + } |
|
447 | + $target[$_] = trim($target[$_]); |
|
448 | + if(!empty($target[$_])) { |
|
449 | + $href = '[~' . $target[$_] . '~]'; |
|
450 | + } |
|
451 | + $array[$c] = '<a href="' . $href . '"' . $v; |
|
452 | + } |
|
453 | + $c++; |
|
454 | + } |
|
455 | + $content = implode('', $array); |
|
456 | + $f['content'] = $modx->db->escape($content); |
|
457 | + $modx->db->update($f, $tbl_site_content, "id='{$id}'"); |
|
458 | + } |
|
459 | 459 | } |