@@ -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 | } |
@@ -10,14 +10,14 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | $__DataGridCnt = 0; |
| 12 | 12 | |
| 13 | -class DataGrid { |
|
| 13 | +class DataGrid{ |
|
| 14 | 14 | |
| 15 | 15 | public $ds; // datasource |
| 16 | 16 | public $id; |
| 17 | - public $pageSize; // pager settings |
|
| 17 | + public $pageSize; // pager settings |
|
| 18 | 18 | public $pageNumber; |
| 19 | 19 | public $pager; |
| 20 | - public $pagerLocation; // top-right, top-left, bottom-left, bottom-right, both-left, both-right |
|
| 20 | + public $pagerLocation; // top-right, top-left, bottom-left, bottom-right, both-left, both-right |
|
| 21 | 21 | |
| 22 | 22 | public $cssStyle; |
| 23 | 23 | public $cssClass; |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | public $colAligns; |
| 36 | 36 | public $colWraps; |
| 37 | 37 | public $colColors; |
| 38 | - public $colTypes; // coltype1, coltype2, etc or coltype1:format1, e.g. date:%Y %m |
|
| 38 | + public $colTypes; // coltype1, coltype2, etc or coltype1:format1, e.g. date:%Y %m |
|
| 39 | 39 | // data type: integer,float,currency,date |
| 40 | 40 | |
| 41 | 41 | public $header; |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | public $cellPadding; |
| 44 | 44 | public $cellSpacing; |
| 45 | 45 | |
| 46 | - public $rowAlign; // vertical alignment: top, middle, bottom |
|
| 46 | + public $rowAlign; // vertical alignment: top, middle, bottom |
|
| 47 | 47 | public $rowIdField; |
| 48 | 48 | |
| 49 | 49 | public $pagerStyle; |
@@ -72,12 +72,12 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | public $cdelim; |
| 74 | 74 | |
| 75 | - public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) { |
|
| 75 | + public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1){ |
|
| 76 | 76 | global $__DataGridCnt; |
| 77 | 77 | |
| 78 | 78 | // set id |
| 79 | 79 | $__DataGridCnt++; |
| 80 | - $this->id = $this->id ? empty($id) : "dg" . $__DataGridCnt; |
|
| 80 | + $this->id = $this->id ? empty($id) : "dg".$__DataGridCnt; |
|
| 81 | 81 | |
| 82 | 82 | // set datasource |
| 83 | 83 | $this->ds = $ds; |
@@ -88,50 +88,50 @@ discard block |
||
| 88 | 88 | $this->pagerLocation = 'top-right'; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - public function setDataSource($ds) { |
|
| 91 | + public function setDataSource($ds){ |
|
| 92 | 92 | $this->ds = $ds; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - public function render() { |
|
| 95 | + public function render(){ |
|
| 96 | 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 . "'" : ''; |
|
| 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 | 101 | |
| 102 | - $pagerClass = ($this->pagerClass) ? "class='" . $this->pagerClass . "'" : ''; |
|
| 103 | - $pagerStyle = ($this->pagerStyle) ? "style='" . $this->pagerStyle . "'" : "style='background-color:#ffffff;'"; |
|
| 102 | + $pagerClass = ($this->pagerClass) ? "class='".$this->pagerClass."'" : ''; |
|
| 103 | + $pagerStyle = ($this->pagerStyle) ? "style='".$this->pagerStyle."'" : "style='background-color:#ffffff;'"; |
|
| 104 | 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 . "'" : ''; |
|
| 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 | 109 | |
| 110 | 110 | $this->_alt = 0; |
| 111 | 111 | $this->_total = 0; |
| 112 | 112 | |
| 113 | 113 | $this->_isDataset = $modx->db->isResult($this->ds); // if not dataset then treat as array |
| 114 | 114 | |
| 115 | - if(!$cssStyle && !$cssClass) { |
|
| 115 | + if (!$cssStyle && !$cssClass) { |
|
| 116 | 116 | $cssStyle = "style='width:100%;border:1px solid silver;font-family:verdana,arial; font-size:11px;'"; |
| 117 | 117 | } |
| 118 | - if(!$columnHeaderStyle && !$columnHeaderClass) { |
|
| 118 | + if (!$columnHeaderStyle && !$columnHeaderClass) { |
|
| 119 | 119 | $columnHeaderStyle = "style='color:black;background-color:silver'"; |
| 120 | 120 | } |
| 121 | - if(!$this->_itemStyle && !$this->_itemClass) { |
|
| 121 | + if (!$this->_itemStyle && !$this->_itemClass) { |
|
| 122 | 122 | $this->_itemStyle = "style='color:black;'"; |
| 123 | 123 | } |
| 124 | - if(!$this->_altItemStyle && !$this->_altItemClass) { |
|
| 124 | + if (!$this->_altItemStyle && !$this->_altItemClass) { |
|
| 125 | 125 | $this->_altItemStyle = "style='color:black;background-color:#eeeeee'"; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - if($this->_isDataset && !$this->columns) { |
|
| 128 | + if ($this->_isDataset && !$this->columns) { |
|
| 129 | 129 | $cols = $modx->db->numFields($this->ds); |
| 130 | - for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->db->fieldName($this->ds, $i); |
|
| 130 | + for ($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "").$modx->db->fieldName($this->ds, $i); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | // start grid |
| 134 | - $tblStart = "<table $cssClass $cssStyle cellpadding='" . (isset($this->cellPadding) ? (int) $this->cellPadding : 1) . "' cellspacing='" . (isset($this->cellSpacing) ? (int) $this->cellSpacing : 1) . "'>"; |
|
| 134 | + $tblStart = "<table $cssClass $cssStyle cellpadding='".(isset($this->cellPadding) ? (int) $this->cellPadding : 1)."' cellspacing='".(isset($this->cellSpacing) ? (int) $this->cellSpacing : 1)."'>"; |
|
| 135 | 135 | $tblEnd = "</table>"; |
| 136 | 136 | |
| 137 | 137 | // build column header |
@@ -142,33 +142,33 @@ discard block |
||
| 142 | 142 | $this->_colcolors = explode((strstr($this->colColors, "||") !== false ? "||" : ","), $this->colColors); |
| 143 | 143 | $this->_coltypes = explode((strstr($this->colTypes, "||") !== false ? "||" : ","), $this->colTypes); |
| 144 | 144 | $this->_colcount = count($this->_colnames); |
| 145 | - if(!$this->_isDataset) { |
|
| 145 | + if (!$this->_isDataset) { |
|
| 146 | 146 | $this->ds = explode((strstr($this->ds, "||") !== false ? "||" : ","), $this->ds); |
| 147 | 147 | $this->ds = array_chunk($this->ds, $this->_colcount); |
| 148 | 148 | } |
| 149 | 149 | $tblColHdr = "<thead><tr>"; |
| 150 | - for($c = 0; $c < $this->_colcount; $c++) { |
|
| 150 | + for ($c = 0; $c < $this->_colcount; $c++) { |
|
| 151 | 151 | $name = $this->_colnames[$c]; |
| 152 | 152 | $width = $this->_colwidths[$c]; |
| 153 | - $tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass" . ($width ? " width='$width'" : "") . ">$name</td>"; |
|
| 153 | + $tblColHdr .= "<td $columnHeaderStyle $columnHeaderClass".($width ? " width='$width'" : "").">$name</td>"; |
|
| 154 | 154 | } |
| 155 | 155 | $tblColHdr .= "</tr></thead>\n"; |
| 156 | 156 | |
| 157 | 157 | // build rows |
| 158 | 158 | $rowcount = $this->_isDataset ? $modx->db->getRecordCount($this->ds) : count($this->ds); |
| 159 | 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"; |
|
| 160 | + if ($rowcount == 0) { |
|
| 161 | + $tblRows .= "<tr><td ".$this->_itemStyle." ".$this->_itemClass." colspan='".$this->_colcount."'>".$this->noRecordMsg."</td></tr>\n"; |
|
| 162 | 162 | } else { |
| 163 | 163 | // render grid items |
| 164 | - if($this->pageSize <= 0) { |
|
| 165 | - for($r = 0; $r < $rowcount; $r++) { |
|
| 164 | + if ($this->pageSize <= 0) { |
|
| 165 | + for ($r = 0; $r < $rowcount; $r++) { |
|
| 166 | 166 | $row = $this->_isDataset ? $modx->db->getRow($this->ds) : $this->ds[$r]; |
| 167 | 167 | $tblRows .= $this->RenderRowFnc($r + 1, $row); |
| 168 | 168 | } |
| 169 | 169 | } else { |
| 170 | - if(!$this->pager) { |
|
| 171 | - include_once dirname(__FILE__) . "/datasetpager.class.php"; |
|
| 170 | + if (!$this->pager) { |
|
| 171 | + include_once dirname(__FILE__)."/datasetpager.class.php"; |
|
| 172 | 172 | $this->pager = new DataSetPager($this->id, $this->ds, $this->pageSize, $this->pageNumber); |
| 173 | 173 | $this->pager->setRenderRowFnc($this); // pass this object |
| 174 | 174 | $this->pager->cssStyle = $pagerStyle; |
@@ -188,18 +188,18 @@ discard block |
||
| 188 | 188 | $o = $tblStart; |
| 189 | 189 | $ptop = (substr($this->pagerLocation, 0, 3) == "top") || (substr($this->pagerLocation, 0, 4) == "both"); |
| 190 | 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>"; |
|
| 191 | + if ($this->header) { |
|
| 192 | + $o .= "<tr><td bgcolor='#ffffff' colspan='".$this->_colcount."'>".$this->header."</td></tr>"; |
|
| 193 | 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>"; |
|
| 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 | 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>"; |
|
| 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 | 200 | } |
| 201 | - if($this->footer) { |
|
| 202 | - $o .= "<tr><td bgcolor='#ffffff' colspan='" . $this->_colcount . "'>" . $this->footer . "</td></tr>"; |
|
| 201 | + if ($this->footer) { |
|
| 202 | + $o .= "<tr><td bgcolor='#ffffff' colspan='".$this->_colcount."'>".$this->footer."</td></tr>"; |
|
| 203 | 203 | } |
| 204 | 204 | $o .= $tblEnd; |
| 205 | 205 | return $o; |
@@ -207,8 +207,8 @@ discard block |
||
| 207 | 207 | |
| 208 | 208 | // format column values |
| 209 | 209 | |
| 210 | - public function RenderRowFnc($n, $row) { |
|
| 211 | - if($this->_alt == 0) { |
|
| 210 | + public function RenderRowFnc($n, $row){ |
|
| 211 | + if ($this->_alt == 0) { |
|
| 212 | 212 | $Style = $this->_itemStyle; |
| 213 | 213 | $Class = $this->_itemClass; |
| 214 | 214 | $this->_alt = 1; |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $this->_alt = 0; |
| 219 | 219 | } |
| 220 | 220 | $o = "<tr>"; |
| 221 | - for($c = 0; $c < $this->_colcount; $c++) { |
|
| 221 | + for ($c = 0; $c < $this->_colcount; $c++) { |
|
| 222 | 222 | $colStyle = $Style; |
| 223 | 223 | $fld = trim($this->_fieldnames[$c]); |
| 224 | 224 | $width = isset($this->_colwidths[$c]) ? $this->_colwidths[$c] : null; |
@@ -227,67 +227,67 @@ discard block |
||
| 227 | 227 | $type = isset($this->_coltypes[$c]) ? $this->_coltypes[$c] : null; |
| 228 | 228 | $nowrap = isset($this->_colwraps[$c]) ? $this->_colwraps[$c] : null; |
| 229 | 229 | $value = $row[($this->_isDataset && $fld ? $fld : $c)]; |
| 230 | - if($color && $Style) { |
|
| 231 | - $colStyle = substr($colStyle, 0, -1) . ";background-color:$color;'"; |
|
| 230 | + if ($color && $Style) { |
|
| 231 | + $colStyle = substr($colStyle, 0, -1).";background-color:$color;'"; |
|
| 232 | 232 | } |
| 233 | 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>"; |
|
| 234 | + $o .= "<td $colStyle $Class".($align ? " align='$align'" : "").($color ? " bgcolor='$color'" : "").($nowrap ? " nowrap='$nowrap'" : "").($width ? " width='$width'" : "").">$value</td>"; |
|
| 235 | 235 | } |
| 236 | 236 | $o .= "</tr>\n"; |
| 237 | 237 | return $o; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - public function formatColumnValue($row, $value, $type, &$align) { |
|
| 241 | - if(strpos($type, ":") !== false) { |
|
| 240 | + public function formatColumnValue($row, $value, $type, &$align){ |
|
| 241 | + if (strpos($type, ":") !== false) { |
|
| 242 | 242 | list($type, $type_format) = explode(":", $type, 2); |
| 243 | 243 | } |
| 244 | - switch(strtolower($type)) { |
|
| 244 | + switch (strtolower($type)) { |
|
| 245 | 245 | case "integer": |
| 246 | - if($align == "") { |
|
| 246 | + if ($align == "") { |
|
| 247 | 247 | $align = "right"; |
| 248 | 248 | } |
| 249 | 249 | $value = number_format($value); |
| 250 | 250 | break; |
| 251 | 251 | |
| 252 | 252 | case "float": |
| 253 | - if($align == "") { |
|
| 253 | + if ($align == "") { |
|
| 254 | 254 | $align = "right"; |
| 255 | 255 | } |
| 256 | - if(!$type_format) { |
|
| 256 | + if (!$type_format) { |
|
| 257 | 257 | $type_format = 2; |
| 258 | 258 | } |
| 259 | 259 | $value = number_format($value, $type_format); |
| 260 | 260 | break; |
| 261 | 261 | |
| 262 | 262 | case "currency": |
| 263 | - if($align == "") { |
|
| 263 | + if ($align == "") { |
|
| 264 | 264 | $align = "right"; |
| 265 | 265 | } |
| 266 | - if(!$type_format) { |
|
| 266 | + if (!$type_format) { |
|
| 267 | 267 | $type_format = 2; |
| 268 | 268 | } |
| 269 | - $value = "$" . number_format($value, $type_format); |
|
| 269 | + $value = "$".number_format($value, $type_format); |
|
| 270 | 270 | break; |
| 271 | 271 | |
| 272 | 272 | case "date": |
| 273 | - if($align == "") { |
|
| 273 | + if ($align == "") { |
|
| 274 | 274 | $align = "right"; |
| 275 | 275 | } |
| 276 | - if(!is_numeric($value)) { |
|
| 276 | + if (!is_numeric($value)) { |
|
| 277 | 277 | $value = strtotime($value); |
| 278 | 278 | } |
| 279 | - if(!$type_format) { |
|
| 279 | + if (!$type_format) { |
|
| 280 | 280 | $type_format = "%A %d, %B %Y"; |
| 281 | 281 | } |
| 282 | 282 | $value = strftime($type_format, $value); |
| 283 | 283 | break; |
| 284 | 284 | |
| 285 | 285 | case "boolean": |
| 286 | - if($align == '') { |
|
| 286 | + if ($align == '') { |
|
| 287 | 287 | $align = "center"; |
| 288 | 288 | } |
| 289 | 289 | $value = number_format($value); |
| 290 | - if($value) { |
|
| 290 | + if ($value) { |
|
| 291 | 291 | $value = '•'; |
| 292 | 292 | } else { |
| 293 | 293 | $value = ' '; |
@@ -298,8 +298,8 @@ discard block |
||
| 298 | 298 | // replace [+value+] first |
| 299 | 299 | $value = str_replace("[+value+]", $value, $type_format); |
| 300 | 300 | // replace other [+fields+] |
| 301 | - if(strpos($value, "[+") !== false) { |
|
| 302 | - foreach($row as $k => $v) { |
|
| 301 | + if (strpos($value, "[+") !== false) { |
|
| 302 | + foreach ($row as $k => $v) { |
|
| 303 | 303 | $value = str_replace("[+$k+]", $v, $value); |
| 304 | 304 | } |
| 305 | 305 | } |
@@ -10,7 +10,8 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | $__DataGridCnt = 0; |
| 12 | 12 | |
| 13 | -class DataGrid { |
|
| 13 | +class DataGrid |
|
| 14 | +{ |
|
| 14 | 15 | |
| 15 | 16 | public $ds; // datasource |
| 16 | 17 | public $id; |
@@ -72,7 +73,8 @@ discard block |
||
| 72 | 73 | */ |
| 73 | 74 | public $cdelim; |
| 74 | 75 | |
| 75 | - public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) { |
|
| 76 | + public function __construct($id, $ds, $pageSize = 20, $pageNumber = -1) |
|
| 77 | + { |
|
| 76 | 78 | global $__DataGridCnt; |
| 77 | 79 | |
| 78 | 80 | // set id |
@@ -88,11 +90,13 @@ discard block |
||
| 88 | 90 | $this->pagerLocation = 'top-right'; |
| 89 | 91 | } |
| 90 | 92 | |
| 91 | - public function setDataSource($ds) { |
|
| 93 | + public function setDataSource($ds) |
|
| 94 | + { |
|
| 92 | 95 | $this->ds = $ds; |
| 93 | 96 | } |
| 94 | 97 | |
| 95 | - public function render() { |
|
| 98 | + public function render() |
|
| 99 | + { |
|
| 96 | 100 | global $modx; |
| 97 | 101 | $columnHeaderStyle = ($this->columnHeaderStyle) ? "style='" . $this->columnHeaderStyle . "'" : ''; |
| 98 | 102 | $columnHeaderClass = ($this->columnHeaderClass) ? "class='" . $this->columnHeaderClass . "'" : ""; |
@@ -127,7 +131,9 @@ discard block |
||
| 127 | 131 | |
| 128 | 132 | if($this->_isDataset && !$this->columns) { |
| 129 | 133 | $cols = $modx->db->numFields($this->ds); |
| 130 | - for($i = 0; $i < $cols; $i++) $this->columns .= ($i ? "," : "") . $modx->db->fieldName($this->ds, $i); |
|
| 134 | + for($i = 0; $i < $cols; $i++) { |
|
| 135 | + $this->columns .= ($i ? "," : "") . $modx->db->fieldName($this->ds, $i); |
|
| 136 | + } |
|
| 131 | 137 | } |
| 132 | 138 | |
| 133 | 139 | // start grid |
@@ -207,7 +213,8 @@ discard block |
||
| 207 | 213 | |
| 208 | 214 | // format column values |
| 209 | 215 | |
| 210 | - public function RenderRowFnc($n, $row) { |
|
| 216 | + public function RenderRowFnc($n, $row) |
|
| 217 | + { |
|
| 211 | 218 | if($this->_alt == 0) { |
| 212 | 219 | $Style = $this->_itemStyle; |
| 213 | 220 | $Class = $this->_itemClass; |
@@ -237,7 +244,8 @@ discard block |
||
| 237 | 244 | return $o; |
| 238 | 245 | } |
| 239 | 246 | |
| 240 | - public function formatColumnValue($row, $value, $type, &$align) { |
|
| 247 | + public function formatColumnValue($row, $value, $type, &$align) |
|
| 248 | + { |
|
| 241 | 249 | if(strpos($type, ":") !== false) { |
| 242 | 250 | list($type, $type_format) = explode(":", $type, 2); |
| 243 | 251 | } |
@@ -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 | } |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | $__DataSetPagerCnt = 0; |
| 12 | 12 | |
| 13 | -class DataSetPager { |
|
| 13 | +class DataSetPager{ |
|
| 14 | 14 | |
| 15 | 15 | public $ds; // datasource |
| 16 | 16 | public $pageSize; |
@@ -31,26 +31,26 @@ discard block |
||
| 31 | 31 | public $renderPagerFnc; |
| 32 | 32 | public $renderPagerFncArgs; |
| 33 | 33 | |
| 34 | - public function __construct($id, $ds, $pageSize = 10, $pageNumber = -1) { |
|
| 34 | + public function __construct($id, $ds, $pageSize = 10, $pageNumber = -1){ |
|
| 35 | 35 | global $_PAGE; // use view state object |
| 36 | 36 | |
| 37 | 37 | global $__DataSetPagerCnt; |
| 38 | 38 | |
| 39 | 39 | // set id |
| 40 | 40 | $__DataSetPagerCnt++; |
| 41 | - $this->id = !empty($id) ? $id : "dsp" . $__DataSetPagerCnt; |
|
| 41 | + $this->id = !empty($id) ? $id : "dsp".$__DataSetPagerCnt; |
|
| 42 | 42 | |
| 43 | 43 | // get pagenumber |
| 44 | 44 | // by setting pager to -1 cause pager to load it's last page number |
| 45 | - if($pageNumber == -1) { |
|
| 45 | + if ($pageNumber == -1) { |
|
| 46 | 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']; |
|
| 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 | 51 | } |
| 52 | 52 | } |
| 53 | - if(!is_numeric($pageNumber)) { |
|
| 53 | + if (!is_numeric($pageNumber)) { |
|
| 54 | 54 | $pageNumber = 1; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -61,40 +61,40 @@ discard block |
||
| 61 | 61 | $this->pager = ''; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - public function getRenderedPager() { |
|
| 64 | + public function getRenderedPager(){ |
|
| 65 | 65 | return $this->pager; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - public function getRenderedRows() { |
|
| 68 | + public function getRenderedRows(){ |
|
| 69 | 69 | return $this->rows; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - public function setDataSource($ds) { |
|
| 72 | + public function setDataSource($ds){ |
|
| 73 | 73 | $this->ds = $ds; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - public function setPageSize($ps) { |
|
| 76 | + public function setPageSize($ps){ |
|
| 77 | 77 | $this->pageSize = $ps; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - public function setRenderRowFnc($fncName, $args = "") { |
|
| 80 | + public function setRenderRowFnc($fncName, $args = ""){ |
|
| 81 | 81 | $this->renderRowFnc = &$fncName; |
| 82 | - $this->renderRowFncArgs = $args; // extra agruments |
|
| 82 | + $this->renderRowFncArgs = $args; // extra agruments |
|
| 83 | 83 | |
| 84 | 84 | |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function setRenderPagerFnc($fncName, $args = "") { |
|
| 87 | + public function setRenderPagerFnc($fncName, $args = ""){ |
|
| 88 | 88 | $this->renderPagerFnc = $fncName; |
| 89 | - $this->renderPagerFncArgs = $args; // extra agruments |
|
| 89 | + $this->renderPagerFncArgs = $args; // extra agruments |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - public function render() { |
|
| 92 | + public function render(){ |
|
| 93 | 93 | global $modx, $_PAGE; |
| 94 | 94 | |
| 95 | 95 | $isDataset = $modx->db->isResult($this->ds); |
| 96 | 96 | |
| 97 | - if(!$this->selPageStyle) { |
|
| 97 | + if (!$this->selPageStyle) { |
|
| 98 | 98 | $this->selPageStyle = "font-weight:bold"; |
| 99 | 99 | } |
| 100 | 100 | |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | $tnr = ($isDataset) ? $modx->db->getRecordCount($this->ds) : count($this->ds); |
| 103 | 103 | |
| 104 | 104 | // render: no records found |
| 105 | - if($tnr <= 0) { |
|
| 105 | + if ($tnr <= 0) { |
|
| 106 | 106 | $fnc = $this->renderRowFnc; |
| 107 | 107 | $args = $this->renderRowFncArgs; |
| 108 | - if(isset($fnc)) { |
|
| 109 | - if($args != "") { |
|
| 108 | + if (isset($fnc)) { |
|
| 109 | + if ($args != "") { |
|
| 110 | 110 | $this->rows .= $fnc(0, null, $args); |
| 111 | 111 | } // if agrs was specified then we will pass three params |
| 112 | 112 | else { |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | // get total pages |
| 120 | 120 | $tp = ceil($tnr / $this->pageSize); |
| 121 | - if($this->pageNumber > $tp) { |
|
| 121 | + if ($this->pageNumber > $tp) { |
|
| 122 | 122 | $this->pageNumber = 1; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -126,39 +126,39 @@ discard block |
||
| 126 | 126 | $p = $this->pageNumber; |
| 127 | 127 | |
| 128 | 128 | // save page number to view state if available |
| 129 | - if(isset($_PAGE['vs'])) { |
|
| 130 | - $_PAGE['vs'][$this->id . '_dpgn'] = $p; |
|
| 129 | + if (isset($_PAGE['vs'])) { |
|
| 130 | + $_PAGE['vs'][$this->id.'_dpgn'] = $p; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | // render pager : renderPagerFnc($cuurentPage,$pagerNumber,$arguments=""); |
| 134 | - if($tp > 1) { |
|
| 134 | + if ($tp > 1) { |
|
| 135 | 135 | $url = ''; |
| 136 | 136 | $fnc = $this->renderPagerFnc; |
| 137 | 137 | $args = $this->renderPagerFncArgs; |
| 138 | - if(!isset($fnc)) { |
|
| 139 | - if($modx->isFrontend()) { |
|
| 140 | - $url = $modx->makeUrl($modx->documentIdentifier, '', '', 'full') . '?'; |
|
| 138 | + if (!isset($fnc)) { |
|
| 139 | + if ($modx->isFrontend()) { |
|
| 140 | + $url = $modx->makeUrl($modx->documentIdentifier, '', '', 'full').'?'; |
|
| 141 | 141 | } else { |
| 142 | - $url = $_SERVER['PHP_SELF'] . '?'; |
|
| 142 | + $url = $_SERVER['PHP_SELF'].'?'; |
|
| 143 | 143 | } |
| 144 | 144 | $i = 0; |
| 145 | - foreach($_GET as $n => $v) if($n != 'dpgn' . $this->id) { |
|
| 145 | + foreach ($_GET as $n => $v) if ($n != 'dpgn'.$this->id) { |
|
| 146 | 146 | $i++; |
| 147 | - $url .= (($i > 1) ? "&" : "") . "$n=$v"; |
|
| 147 | + $url .= (($i > 1) ? "&" : "")."$n=$v"; |
|
| 148 | 148 | } |
| 149 | - if($i >= 1) { |
|
| 149 | + if ($i >= 1) { |
|
| 150 | 150 | $url .= "&"; |
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | - for($i = 1; $i <= $tp; $i++) { |
|
| 154 | - if(isset($fnc)) { |
|
| 155 | - if($args != "") { |
|
| 153 | + for ($i = 1; $i <= $tp; $i++) { |
|
| 154 | + if (isset($fnc)) { |
|
| 155 | + if ($args != "") { |
|
| 156 | 156 | $this->pager .= $fnc($p, $i, $args); |
| 157 | 157 | } else { |
| 158 | 158 | $this->pager .= $fnc($p, $i); |
| 159 | 159 | } |
| 160 | 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> "; |
|
| 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 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | } |
@@ -167,21 +167,21 @@ discard block |
||
| 167 | 167 | $fnc = $this->renderRowFnc; |
| 168 | 168 | $args = $this->renderRowFncArgs; |
| 169 | 169 | |
| 170 | - if(isset($fnc)) { |
|
| 170 | + if (isset($fnc)) { |
|
| 171 | 171 | $i = 1; |
| 172 | 172 | $fncObject = is_object($fnc); |
| 173 | 173 | $minitems = (($p - 1) * $this->pageSize) + 1; |
| 174 | 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 != "") { |
|
| 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 | 179 | $this->rows .= $fnc->RenderRowFnc($i, $row, $args); |
| 180 | 180 | } else { |
| 181 | 181 | $this->rows .= $fnc->RenderRowFnc($i, $row); |
| 182 | 182 | } |
| 183 | 183 | } else { |
| 184 | - if($args != "") { |
|
| 184 | + if ($args != "") { |
|
| 185 | 185 | $this->rows .= $fnc($i, $row, $args); |
| 186 | 186 | } // if agrs was specified then we wil pass three params |
| 187 | 187 | else { |
@@ -10,7 +10,8 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | $__DataSetPagerCnt = 0; |
| 12 | 12 | |
| 13 | -class DataSetPager { |
|
| 13 | +class DataSetPager |
|
| 14 | +{ |
|
| 14 | 15 | |
| 15 | 16 | public $ds; // datasource |
| 16 | 17 | public $pageSize; |
@@ -31,7 +32,8 @@ discard block |
||
| 31 | 32 | public $renderPagerFnc; |
| 32 | 33 | public $renderPagerFncArgs; |
| 33 | 34 | |
| 34 | - public function __construct($id, $ds, $pageSize = 10, $pageNumber = -1) { |
|
| 35 | + public function __construct($id, $ds, $pageSize = 10, $pageNumber = -1) |
|
| 36 | + { |
|
| 35 | 37 | global $_PAGE; // use view state object |
| 36 | 38 | |
| 37 | 39 | global $__DataSetPagerCnt; |
@@ -61,35 +63,42 @@ discard block |
||
| 61 | 63 | $this->pager = ''; |
| 62 | 64 | } |
| 63 | 65 | |
| 64 | - public function getRenderedPager() { |
|
| 66 | + public function getRenderedPager() |
|
| 67 | + { |
|
| 65 | 68 | return $this->pager; |
| 66 | 69 | } |
| 67 | 70 | |
| 68 | - public function getRenderedRows() { |
|
| 71 | + public function getRenderedRows() |
|
| 72 | + { |
|
| 69 | 73 | return $this->rows; |
| 70 | 74 | } |
| 71 | 75 | |
| 72 | - public function setDataSource($ds) { |
|
| 76 | + public function setDataSource($ds) |
|
| 77 | + { |
|
| 73 | 78 | $this->ds = $ds; |
| 74 | 79 | } |
| 75 | 80 | |
| 76 | - public function setPageSize($ps) { |
|
| 81 | + public function setPageSize($ps) |
|
| 82 | + { |
|
| 77 | 83 | $this->pageSize = $ps; |
| 78 | 84 | } |
| 79 | 85 | |
| 80 | - public function setRenderRowFnc($fncName, $args = "") { |
|
| 86 | + public function setRenderRowFnc($fncName, $args = "") |
|
| 87 | + { |
|
| 81 | 88 | $this->renderRowFnc = &$fncName; |
| 82 | 89 | $this->renderRowFncArgs = $args; // extra agruments |
| 83 | 90 | |
| 84 | 91 | |
| 85 | 92 | } |
| 86 | 93 | |
| 87 | - public function setRenderPagerFnc($fncName, $args = "") { |
|
| 94 | + public function setRenderPagerFnc($fncName, $args = "") |
|
| 95 | + { |
|
| 88 | 96 | $this->renderPagerFnc = $fncName; |
| 89 | 97 | $this->renderPagerFncArgs = $args; // extra agruments |
| 90 | 98 | } |
| 91 | 99 | |
| 92 | - public function render() { |
|
| 100 | + public function render() |
|
| 101 | + { |
|
| 93 | 102 | global $modx, $_PAGE; |
| 94 | 103 | |
| 95 | 104 | $isDataset = $modx->db->isResult($this->ds); |
@@ -142,8 +151,10 @@ discard block |
||
| 142 | 151 | $url = $_SERVER['PHP_SELF'] . '?'; |
| 143 | 152 | } |
| 144 | 153 | $i = 0; |
| 145 | - foreach($_GET as $n => $v) if($n != 'dpgn' . $this->id) { |
|
| 154 | + foreach($_GET as $n => $v) { |
|
| 155 | + if($n != 'dpgn' . $this->id) { |
|
| 146 | 156 | $i++; |
| 157 | + } |
|
| 147 | 158 | $url .= (($i > 1) ? "&" : "") . "$n=$v"; |
| 148 | 159 | } |
| 149 | 160 | if($i >= 1) { |
@@ -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 | */ |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | */ |
| 206 | 206 | function __call($method_name, $arguments) |
| 207 | 207 | { |
| 208 | - include_once(MODX_MANAGER_PATH . 'includes/extenders/deprecated.functions.inc.php'); |
|
| 208 | + include_once(MODX_MANAGER_PATH.'includes/extenders/deprecated.functions.inc.php'); |
|
| 209 | 209 | if (method_exists($this->old, $method_name)) { |
| 210 | 210 | $error_type = 1; |
| 211 | 211 | } else { |
@@ -223,12 +223,12 @@ discard block |
||
| 223 | 223 | $info = debug_backtrace(); |
| 224 | 224 | $m[] = $msg; |
| 225 | 225 | if (!empty($this->currentSnippet)) { |
| 226 | - $m[] = 'Snippet - ' . $this->currentSnippet; |
|
| 226 | + $m[] = 'Snippet - '.$this->currentSnippet; |
|
| 227 | 227 | } elseif (!empty($this->event->activePlugin)) { |
| 228 | - $m[] = 'Plugin - ' . $this->event->activePlugin; |
|
| 228 | + $m[] = 'Plugin - '.$this->event->activePlugin; |
|
| 229 | 229 | } |
| 230 | 230 | $m[] = $this->decoded_request_uri; |
| 231 | - $m[] = str_replace('\\', '/', $info[0]['file']) . '(line:' . $info[0]['line'] . ')'; |
|
| 231 | + $m[] = str_replace('\\', '/', $info[0]['file']).'(line:'.$info[0]['line'].')'; |
|
| 232 | 232 | $msg = implode('<br />', $m); |
| 233 | 233 | $this->logEvent(0, $error_type, $msg, $title); |
| 234 | 234 | } |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | { |
| 246 | 246 | $flag = false; |
| 247 | 247 | if (is_scalar($connector) && !empty($connector) && isset($this->{$connector}) && $this->{$connector} instanceof DBAPI) { |
| 248 | - $flag = (bool)$this->{$connector}->conn; |
|
| 248 | + $flag = (bool) $this->{$connector}->conn; |
|
| 249 | 249 | } |
| 250 | 250 | return $flag; |
| 251 | 251 | } |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | if (!$out && $flag) { |
| 274 | 274 | $extname = trim(str_replace(array('..', '/', '\\'), '', strtolower($extname))); |
| 275 | - $filename = MODX_MANAGER_PATH . "includes/extenders/ex_{$extname}.inc.php"; |
|
| 275 | + $filename = MODX_MANAGER_PATH."includes/extenders/ex_{$extname}.inc.php"; |
|
| 276 | 276 | $out = is_file($filename) ? include $filename : false; |
| 277 | 277 | } |
| 278 | 278 | if ($out && !in_array($extname, $this->extensions)) { |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | public function getMicroTime() |
| 290 | 290 | { |
| 291 | 291 | list ($usec, $sec) = explode(' ', microtime()); |
| 292 | - return ((float)$usec + (float)$sec); |
|
| 292 | + return ((float) $usec + (float) $sec); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | // append the redirect count string to the url |
| 314 | 314 | $currentNumberOfRedirects = isset ($_REQUEST['err']) ? $_REQUEST['err'] : 0; |
| 315 | 315 | if ($currentNumberOfRedirects > 3) { |
| 316 | - $this->messageQuit('Redirection attempt failed - please ensure the document you\'re trying to redirect to exists. <p>Redirection URL: <i>' . $url . '</i></p>'); |
|
| 316 | + $this->messageQuit('Redirection attempt failed - please ensure the document you\'re trying to redirect to exists. <p>Redirection URL: <i>'.$url.'</i></p>'); |
|
| 317 | 317 | } else { |
| 318 | 318 | $currentNumberOfRedirects += 1; |
| 319 | 319 | if (strpos($url, "?") > 0) { |
@@ -324,9 +324,9 @@ discard block |
||
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | if ($type == 'REDIRECT_REFRESH') { |
| 327 | - $header = 'Refresh: 0;URL=' . $url; |
|
| 327 | + $header = 'Refresh: 0;URL='.$url; |
|
| 328 | 328 | } elseif ($type == 'REDIRECT_META') { |
| 329 | - $header = '<META HTTP-EQUIV="Refresh" CONTENT="0; URL=' . $url . '" />'; |
|
| 329 | + $header = '<META HTTP-EQUIV="Refresh" CONTENT="0; URL='.$url.'" />'; |
|
| 330 | 330 | echo $header; |
| 331 | 331 | exit; |
| 332 | 332 | } elseif ($type == 'REDIRECT_HEADER' || empty ($type)) { |
@@ -334,10 +334,10 @@ discard block |
||
| 334 | 334 | global $base_url, $site_url; |
| 335 | 335 | if (substr($url, 0, strlen($base_url)) == $base_url) { |
| 336 | 336 | // append $site_url to make it work with Location: |
| 337 | - $url = $site_url . substr($url, strlen($base_url)); |
|
| 337 | + $url = $site_url.substr($url, strlen($base_url)); |
|
| 338 | 338 | } |
| 339 | 339 | if (strpos($url, "\n") === false) { |
| 340 | - $header = 'Location: ' . $url; |
|
| 340 | + $header = 'Location: '.$url; |
|
| 341 | 341 | } else { |
| 342 | 342 | $this->messageQuit('No newline allowed in redirect url.'); |
| 343 | 343 | } |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | header($responseCode); |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - if(!empty($header)) { |
|
| 349 | + if (!empty($header)) { |
|
| 350 | 350 | header($header); |
| 351 | 351 | } |
| 352 | 352 | |
@@ -450,8 +450,8 @@ discard block |
||
| 450 | 450 | |
| 451 | 451 | private function recoverySiteCache() |
| 452 | 452 | { |
| 453 | - $site_cache_dir = MODX_BASE_PATH . $this->getCacheFolder(); |
|
| 454 | - $site_cache_path = $site_cache_dir . 'siteCache.idx.php'; |
|
| 453 | + $site_cache_dir = MODX_BASE_PATH.$this->getCacheFolder(); |
|
| 454 | + $site_cache_path = $site_cache_dir.'siteCache.idx.php'; |
|
| 455 | 455 | |
| 456 | 456 | if (is_file($site_cache_path)) { |
| 457 | 457 | include($site_cache_path); |
@@ -460,7 +460,7 @@ discard block |
||
| 460 | 460 | return; |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | - include_once(MODX_MANAGER_PATH . 'processors/cache_sync.class.processor.php'); |
|
| 463 | + include_once(MODX_MANAGER_PATH.'processors/cache_sync.class.processor.php'); |
|
| 464 | 464 | $cache = new synccache(); |
| 465 | 465 | $cache->setCachepath($site_cache_dir); |
| 466 | 466 | $cache->setReport(false); |
@@ -511,8 +511,8 @@ discard block |
||
| 511 | 511 | $this->invokeEvent("OnBeforeManagerPageInit"); |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | - if (isset ($_SESSION[$usrType . 'UsrConfigSet'])) { |
|
| 515 | - $usrSettings = &$_SESSION[$usrType . 'UsrConfigSet']; |
|
| 514 | + if (isset ($_SESSION[$usrType.'UsrConfigSet'])) { |
|
| 515 | + $usrSettings = &$_SESSION[$usrType.'UsrConfigSet']; |
|
| 516 | 516 | } else { |
| 517 | 517 | if ($usrType == 'web') { |
| 518 | 518 | $from = $tbl_web_user_settings; |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | $usrSettings[$row['setting_name']] = $row['setting_value']; |
| 533 | 533 | } |
| 534 | 534 | if (isset ($usrType)) { |
| 535 | - $_SESSION[$usrType . 'UsrConfigSet'] = $usrSettings; |
|
| 535 | + $_SESSION[$usrType.'UsrConfigSet'] = $usrSettings; |
|
| 536 | 536 | } // store user settings in session |
| 537 | 537 | } |
| 538 | 538 | } |
@@ -677,10 +677,10 @@ discard block |
||
| 677 | 677 | $suf = $this->config['friendly_url_suffix']; |
| 678 | 678 | $pre = preg_quote($pre, '/'); |
| 679 | 679 | $suf = preg_quote($suf, '/'); |
| 680 | - if ($pre && preg_match('@^' . $pre . '(.*)$@', $q, $_)) { |
|
| 680 | + if ($pre && preg_match('@^'.$pre.'(.*)$@', $q, $_)) { |
|
| 681 | 681 | $q = $_[1]; |
| 682 | 682 | } |
| 683 | - if ($suf && preg_match('@(.*)' . $suf . '$@', $q, $_)) { |
|
| 683 | + if ($suf && preg_match('@(.*)'.$suf.'$@', $q, $_)) { |
|
| 684 | 684 | $q = $_[1]; |
| 685 | 685 | } |
| 686 | 686 | |
@@ -702,7 +702,7 @@ discard block |
||
| 702 | 702 | if (preg_match('@^[1-9][0-9]*$@', $q) && !isset($this->documentListing[$q])) { /* we got an ID returned, check to make sure it's not an alias */ |
| 703 | 703 | /* FS#476 and FS#308: check that id is valid in terms of virtualDir structure */ |
| 704 | 704 | if ($this->config['use_alias_path'] == 1) { |
| 705 | - if (($this->virtualDir != '' && !isset($this->documentListing[$this->virtualDir . '/' . $q]) || ($this->virtualDir == '' && !isset($this->documentListing[$q]))) && (($this->virtualDir != '' && isset($this->documentListing[$this->virtualDir]) && in_array($q, $this->getChildIds($this->documentListing[$this->virtualDir], 1))) || ($this->virtualDir == '' && in_array($q, $this->getChildIds(0, 1))))) { |
|
| 705 | + if (($this->virtualDir != '' && !isset($this->documentListing[$this->virtualDir.'/'.$q]) || ($this->virtualDir == '' && !isset($this->documentListing[$q]))) && (($this->virtualDir != '' && isset($this->documentListing[$this->virtualDir]) && in_array($q, $this->getChildIds($this->documentListing[$this->virtualDir], 1))) || ($this->virtualDir == '' && in_array($q, $this->getChildIds(0, 1))))) { |
|
| 706 | 706 | $this->documentMethod = 'id'; |
| 707 | 707 | return $q; |
| 708 | 708 | } else { /* not a valid id in terms of virtualDir, treat as alias */ |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | */ |
| 737 | 737 | public function getHashFile($key) |
| 738 | 738 | { |
| 739 | - return $this->getCacheFolder() . "docid_" . $key . ".pageCache.php"; |
|
| 739 | + return $this->getCacheFolder()."docid_".$key.".pageCache.php"; |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | /** |
@@ -747,9 +747,9 @@ discard block |
||
| 747 | 747 | $hash = $id; |
| 748 | 748 | $tmp = null; |
| 749 | 749 | $params = array(); |
| 750 | - if(!empty($this->systemCacheKey)){ |
|
| 750 | + if (!empty($this->systemCacheKey)) { |
|
| 751 | 751 | $hash = $this->systemCacheKey; |
| 752 | - }else { |
|
| 752 | + } else { |
|
| 753 | 753 | if (!empty($_GET)) { |
| 754 | 754 | // Sort GET parameters so that the order of parameters on the HTTP request don't affect the generated cache ID. |
| 755 | 755 | $params = $_GET; |
@@ -757,8 +757,8 @@ discard block |
||
| 757 | 757 | $hash .= '_'.md5(http_build_query($params)); |
| 758 | 758 | } |
| 759 | 759 | } |
| 760 | - $evtOut = $this->invokeEvent("OnMakePageCacheKey", array ("hash" => $hash, "id" => $id, 'params' => $params)); |
|
| 761 | - if (is_array($evtOut) && count($evtOut) > 0){ |
|
| 760 | + $evtOut = $this->invokeEvent("OnMakePageCacheKey", array("hash" => $hash, "id" => $id, 'params' => $params)); |
|
| 761 | + if (is_array($evtOut) && count($evtOut) > 0) { |
|
| 762 | 762 | $tmp = array_pop($evtOut); |
| 763 | 763 | } |
| 764 | 764 | return empty($tmp) ? $hash : $tmp; |
@@ -900,12 +900,12 @@ discard block |
||
| 900 | 900 | if ($js = $this->getRegisteredClientStartupScripts()) { |
| 901 | 901 | // change to just before closing </head> |
| 902 | 902 | // $this->documentContent = preg_replace("/(<head[^>]*>)/i", "\\1\n".$js, $this->documentContent); |
| 903 | - $this->documentOutput = preg_replace("/(<\/head>)/i", $js . "\n\\1", $this->documentOutput); |
|
| 903 | + $this->documentOutput = preg_replace("/(<\/head>)/i", $js."\n\\1", $this->documentOutput); |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | // Insert jscripts & html block into template - template must have a </body> tag |
| 907 | 907 | if ($js = $this->getRegisteredClientScripts()) { |
| 908 | - $this->documentOutput = preg_replace("/(<\/body>)/i", $js . "\n\\1", $this->documentOutput); |
|
| 908 | + $this->documentOutput = preg_replace("/(<\/body>)/i", $js."\n\\1", $this->documentOutput); |
|
| 909 | 909 | } |
| 910 | 910 | // End fix by sirlancelot |
| 911 | 911 | |
@@ -916,7 +916,7 @@ discard block |
||
| 916 | 916 | // send out content-type and content-disposition headers |
| 917 | 917 | if (IN_PARSER_MODE == "true") { |
| 918 | 918 | $type = !empty ($this->contentTypes[$this->documentIdentifier]) ? $this->contentTypes[$this->documentIdentifier] : "text/html"; |
| 919 | - header('Content-Type: ' . $type . '; charset=' . $this->config['modx_charset']); |
|
| 919 | + header('Content-Type: '.$type.'; charset='.$this->config['modx_charset']); |
|
| 920 | 920 | // if (($this->documentIdentifier == $this->config['error_page']) || $redirect_error) |
| 921 | 921 | // header('HTTP/1.0 404 Not Found'); |
| 922 | 922 | if (!$this->checkPreview() && $this->documentObject['content_dispo'] == 1) { |
@@ -934,7 +934,7 @@ discard block |
||
| 934 | 934 | $name = preg_replace('|-+|', '-', $name); |
| 935 | 935 | $name = trim($name, '-'); |
| 936 | 936 | } |
| 937 | - $header = 'Content-Disposition: attachment; filename=' . $name; |
|
| 937 | + $header = 'Content-Disposition: attachment; filename='.$name; |
|
| 938 | 938 | header($header); |
| 939 | 939 | } |
| 940 | 940 | } |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | |
| 943 | 943 | $stats = $this->getTimerStats($this->tstart); |
| 944 | 944 | |
| 945 | - $out =& $this->documentOutput; |
|
| 945 | + $out = & $this->documentOutput; |
|
| 946 | 946 | $out = str_replace("[^q^]", $stats['queries'], $out); |
| 947 | 947 | $out = str_replace("[^qt^]", $stats['queryTime'], $out); |
| 948 | 948 | $out = str_replace("[^p^]", $stats['phpTime'], $out); |
@@ -981,17 +981,17 @@ discard block |
||
| 981 | 981 | $sc .= sprintf("%s. %s (%s)<br>", $s, $sname, sprintf("%2.2f ms", $t)); // currentSnippet |
| 982 | 982 | $tt += $t; |
| 983 | 983 | } |
| 984 | - echo "<fieldset><legend><b>Snippets</b> (" . count($this->snippetsTime) . " / " . sprintf("%2.2f ms", $tt) . ")</legend>{$sc}</fieldset><br />"; |
|
| 984 | + echo "<fieldset><legend><b>Snippets</b> (".count($this->snippetsTime)." / ".sprintf("%2.2f ms", $tt).")</legend>{$sc}</fieldset><br />"; |
|
| 985 | 985 | echo $this->snippetsCode; |
| 986 | 986 | } |
| 987 | 987 | if ($this->dumpPlugins) { |
| 988 | 988 | $ps = ""; |
| 989 | 989 | $tt = 0; |
| 990 | 990 | foreach ($this->pluginsTime as $s => $t) { |
| 991 | - $ps .= "$s (" . sprintf("%2.2f ms", $t * 1000) . ")<br>"; |
|
| 991 | + $ps .= "$s (".sprintf("%2.2f ms", $t * 1000).")<br>"; |
|
| 992 | 992 | $tt += $t; |
| 993 | 993 | } |
| 994 | - echo "<fieldset><legend><b>Plugins</b> (" . count($this->pluginsTime) . " / " . sprintf("%2.2f ms", $tt * 1000) . ")</legend>{$ps}</fieldset><br />"; |
|
| 994 | + echo "<fieldset><legend><b>Plugins</b> (".count($this->pluginsTime)." / ".sprintf("%2.2f ms", $tt * 1000).")</legend>{$ps}</fieldset><br />"; |
|
| 995 | 995 | echo $this->pluginsCode; |
| 996 | 996 | } |
| 997 | 997 | |
@@ -1017,7 +1017,7 @@ discard block |
||
| 1017 | 1017 | $srcTags = explode(',', $tags); |
| 1018 | 1018 | $repTags = array(); |
| 1019 | 1019 | foreach ($srcTags as $tag) { |
| 1020 | - $repTags[] = '\\' . $tag[0] . '\\' . $tag[1]; |
|
| 1020 | + $repTags[] = '\\'.$tag[0].'\\'.$tag[1]; |
|
| 1021 | 1021 | } |
| 1022 | 1022 | return array($srcTags, $repTags); |
| 1023 | 1023 | } |
@@ -1039,7 +1039,7 @@ discard block |
||
| 1039 | 1039 | $stats['phpTime'] = sprintf("%2.4f s", $stats['phpTime']); |
| 1040 | 1040 | $stats['source'] = $this->documentGenerated == 1 ? "database" : "cache"; |
| 1041 | 1041 | $stats['queries'] = isset ($this->executedQueries) ? $this->executedQueries : 0; |
| 1042 | - $stats['phpMemory'] = (memory_get_peak_usage(true) / 1024 / 1024) . " mb"; |
|
| 1042 | + $stats['phpMemory'] = (memory_get_peak_usage(true) / 1024 / 1024)." mb"; |
|
| 1043 | 1043 | |
| 1044 | 1044 | return $stats; |
| 1045 | 1045 | } |
@@ -1072,7 +1072,7 @@ discard block |
||
| 1072 | 1072 | { |
| 1073 | 1073 | $cacheRefreshTime = 0; |
| 1074 | 1074 | $recent_update = 0; |
| 1075 | - @include(MODX_BASE_PATH . $this->getCacheFolder() . 'sitePublishing.idx.php'); |
|
| 1075 | + @include(MODX_BASE_PATH.$this->getCacheFolder().'sitePublishing.idx.php'); |
|
| 1076 | 1076 | $this->recentUpdate = $recent_update; |
| 1077 | 1077 | |
| 1078 | 1078 | $timeNow = $_SERVER['REQUEST_TIME'] + $this->config['server_offset_time']; |
@@ -1126,8 +1126,8 @@ discard block |
||
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | 1128 | $docObjSerial = serialize($this->documentObject); |
| 1129 | - $cacheContent = $docObjSerial . "<!--__MODxCacheSpliter__-->" . $this->documentContent; |
|
| 1130 | - $page_cache_path = MODX_BASE_PATH . $this->getHashFile($this->cacheKey); |
|
| 1129 | + $cacheContent = $docObjSerial."<!--__MODxCacheSpliter__-->".$this->documentContent; |
|
| 1130 | + $page_cache_path = MODX_BASE_PATH.$this->getHashFile($this->cacheKey); |
|
| 1131 | 1131 | file_put_contents($page_cache_path, "<?php die('Unauthorized access.'); ?>$cacheContent"); |
| 1132 | 1132 | } |
| 1133 | 1133 | } |
@@ -1169,16 +1169,16 @@ discard block |
||
| 1169 | 1169 | return array(); |
| 1170 | 1170 | } |
| 1171 | 1171 | $spacer = md5('<<<EVO>>>'); |
| 1172 | - if($left==='{{' && strpos($content,';}}')!==false) $content = str_replace(';}}', sprintf(';}%s}', $spacer),$content); |
|
| 1173 | - if($left==='{{' && strpos($content,'{{}}')!==false) $content = str_replace('{{}}',sprintf('{%$1s{}%$1s}',$spacer),$content); |
|
| 1174 | - if($left==='[[' && strpos($content,']]]]')!==false) $content = str_replace(']]]]',sprintf(']]%s]]', $spacer),$content); |
|
| 1175 | - if($left==='[[' && strpos($content,']]]')!==false) $content = str_replace(']]]', sprintf(']%s]]', $spacer),$content); |
|
| 1172 | + if ($left === '{{' && strpos($content, ';}}') !== false) $content = str_replace(';}}', sprintf(';}%s}', $spacer), $content); |
|
| 1173 | + if ($left === '{{' && strpos($content, '{{}}') !== false) $content = str_replace('{{}}', sprintf('{%$1s{}%$1s}', $spacer), $content); |
|
| 1174 | + if ($left === '[[' && strpos($content, ']]]]') !== false) $content = str_replace(']]]]', sprintf(']]%s]]', $spacer), $content); |
|
| 1175 | + if ($left === '[[' && strpos($content, ']]]') !== false) $content = str_replace(']]]', sprintf(']%s]]', $spacer), $content); |
|
| 1176 | 1176 | |
| 1177 | 1177 | $pos['<![CDATA['] = strpos($content, '<![CDATA['); |
| 1178 | 1178 | $pos[']]>'] = strpos($content, ']]>'); |
| 1179 | 1179 | |
| 1180 | 1180 | if ($pos['<![CDATA['] !== false && $pos[']]>'] !== false) { |
| 1181 | - $content = substr($content, 0, $pos['<![CDATA[']) . substr($content, $pos[']]>'] + 3); |
|
| 1181 | + $content = substr($content, 0, $pos['<![CDATA[']).substr($content, $pos[']]>'] + 3); |
|
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | $lp = explode($left, $content); |
@@ -1242,8 +1242,8 @@ discard block |
||
| 1242 | 1242 | } |
| 1243 | 1243 | } |
| 1244 | 1244 | } |
| 1245 | - foreach($tags as $i=>$tag) { |
|
| 1246 | - if(strpos($tag,$spacer)!==false) $tags[$i] = str_replace($spacer, '', $tag); |
|
| 1245 | + foreach ($tags as $i=>$tag) { |
|
| 1246 | + if (strpos($tag, $spacer) !== false) $tags[$i] = str_replace($spacer, '', $tag); |
|
| 1247 | 1247 | } |
| 1248 | 1248 | return $tags; |
| 1249 | 1249 | } |
@@ -1283,7 +1283,7 @@ discard block |
||
| 1283 | 1283 | } |
| 1284 | 1284 | |
| 1285 | 1285 | foreach ($matches[1] as $i => $key) { |
| 1286 | - if(strpos($key,'[+')!==false) continue; // Allow chunk {{chunk?¶m=`xxx`}} with [*tv_name_[+param+]*] as content |
|
| 1286 | + if (strpos($key, '[+') !== false) continue; // Allow chunk {{chunk?¶m=`xxx`}} with [*tv_name_[+param+]*] as content |
|
| 1287 | 1287 | if (substr($key, 0, 1) == '#') { |
| 1288 | 1288 | $key = substr($key, 1); |
| 1289 | 1289 | } // remove # for QuickEdit format |
@@ -1303,8 +1303,8 @@ discard block |
||
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | 1305 | if (is_array($value)) { |
| 1306 | - include_once(MODX_MANAGER_PATH . 'includes/tmplvars.format.inc.php'); |
|
| 1307 | - include_once(MODX_MANAGER_PATH . 'includes/tmplvars.commands.inc.php'); |
|
| 1306 | + include_once(MODX_MANAGER_PATH.'includes/tmplvars.format.inc.php'); |
|
| 1307 | + include_once(MODX_MANAGER_PATH.'includes/tmplvars.commands.inc.php'); |
|
| 1308 | 1308 | $value = getTVDisplayFormat($value[0], $value[1], $value[2], $value[3], $value[4]); |
| 1309 | 1309 | } |
| 1310 | 1310 | |
@@ -1315,8 +1315,8 @@ discard block |
||
| 1315 | 1315 | |
| 1316 | 1316 | if (strpos($content, $s) !== false) { |
| 1317 | 1317 | $content = str_replace($s, $value, $content); |
| 1318 | - } elseif($this->debug) { |
|
| 1319 | - $this->addLog('mergeDocumentContent parse error', $_SERVER['REQUEST_URI'] . $s, 2); |
|
| 1318 | + } elseif ($this->debug) { |
|
| 1319 | + $this->addLog('mergeDocumentContent parse error', $_SERVER['REQUEST_URI'].$s, 2); |
|
| 1320 | 1320 | } |
| 1321 | 1321 | } |
| 1322 | 1322 | |
@@ -1483,8 +1483,8 @@ discard block |
||
| 1483 | 1483 | $s = &$matches[0][$i]; |
| 1484 | 1484 | if (strpos($content, $s) !== false) { |
| 1485 | 1485 | $content = str_replace($s, $value, $content); |
| 1486 | - } elseif($this->debug) { |
|
| 1487 | - $this->addLog('mergeSettingsContent parse error', $_SERVER['REQUEST_URI'] . $s, 2); |
|
| 1486 | + } elseif ($this->debug) { |
|
| 1487 | + $this->addLog('mergeSettingsContent parse error', $_SERVER['REQUEST_URI'].$s, 2); |
|
| 1488 | 1488 | } |
| 1489 | 1489 | } |
| 1490 | 1490 | return $content; |
@@ -1537,7 +1537,7 @@ discard block |
||
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | 1539 | $value = $this->parseText($value, $params); // parse local scope placeholers for ConditionalTags |
| 1540 | - $value = $this->mergePlaceholderContent($value, $params); // parse page global placeholers |
|
| 1540 | + $value = $this->mergePlaceholderContent($value, $params); // parse page global placeholers |
|
| 1541 | 1541 | if ($this->config['enable_at_syntax']) { |
| 1542 | 1542 | $value = $this->mergeConditionalTagsContent($value); |
| 1543 | 1543 | } |
@@ -1552,8 +1552,8 @@ discard block |
||
| 1552 | 1552 | $s = &$matches[0][$i]; |
| 1553 | 1553 | if (strpos($content, $s) !== false) { |
| 1554 | 1554 | $content = str_replace($s, $value, $content); |
| 1555 | - } elseif($this->debug) { |
|
| 1556 | - $this->addLog('mergeChunkContent parse error', $_SERVER['REQUEST_URI'] . $s, 2); |
|
| 1555 | + } elseif ($this->debug) { |
|
| 1556 | + $this->addLog('mergeChunkContent parse error', $_SERVER['REQUEST_URI'].$s, 2); |
|
| 1557 | 1557 | } |
| 1558 | 1558 | } |
| 1559 | 1559 | return $content; |
@@ -1611,8 +1611,8 @@ discard block |
||
| 1611 | 1611 | $s = &$matches[0][$i]; |
| 1612 | 1612 | if (strpos($content, $s) !== false) { |
| 1613 | 1613 | $content = str_replace($s, $value, $content); |
| 1614 | - } elseif($this->debug) { |
|
| 1615 | - $this->addLog('mergePlaceholderContent parse error', $_SERVER['REQUEST_URI'] . $s, 2); |
|
| 1614 | + } elseif ($this->debug) { |
|
| 1615 | + $this->addLog('mergePlaceholderContent parse error', $_SERVER['REQUEST_URI'].$s, 2); |
|
| 1616 | 1616 | } |
| 1617 | 1617 | } |
| 1618 | 1618 | return $content; |
@@ -1636,7 +1636,7 @@ discard block |
||
| 1636 | 1636 | return $content; |
| 1637 | 1637 | } |
| 1638 | 1638 | |
| 1639 | - $sp = '#' . md5('ConditionalTags' . $_SERVER['REQUEST_TIME']) . '#'; |
|
| 1639 | + $sp = '#'.md5('ConditionalTags'.$_SERVER['REQUEST_TIME']).'#'; |
|
| 1640 | 1640 | $content = str_replace(array('<?php', '<?=', '<?', '?>'), array("{$sp}b", "{$sp}p", "{$sp}s", "{$sp}e"), $content); |
| 1641 | 1641 | |
| 1642 | 1642 | $pieces = explode('<@IF:', $content); |
@@ -1647,7 +1647,7 @@ discard block |
||
| 1647 | 1647 | } |
| 1648 | 1648 | list($cmd, $text) = explode('>', $split, 2); |
| 1649 | 1649 | $cmd = str_replace("'", "\'", $cmd); |
| 1650 | - $content .= "<?php if(\$this->_parseCTagCMD('" . $cmd . "')): ?>"; |
|
| 1650 | + $content .= "<?php if(\$this->_parseCTagCMD('".$cmd."')): ?>"; |
|
| 1651 | 1651 | $content .= $text; |
| 1652 | 1652 | } |
| 1653 | 1653 | $pieces = explode('<@ELSEIF:', $content); |
@@ -1658,13 +1658,13 @@ discard block |
||
| 1658 | 1658 | } |
| 1659 | 1659 | list($cmd, $text) = explode('>', $split, 2); |
| 1660 | 1660 | $cmd = str_replace("'", "\'", $cmd); |
| 1661 | - $content .= "<?php elseif(\$this->_parseCTagCMD('" . $cmd . "')): ?>"; |
|
| 1661 | + $content .= "<?php elseif(\$this->_parseCTagCMD('".$cmd."')): ?>"; |
|
| 1662 | 1662 | $content .= $text; |
| 1663 | 1663 | } |
| 1664 | 1664 | |
| 1665 | 1665 | $content = str_replace(array('<@ELSE>', '<@ENDIF>'), array('<?php else:?>', '<?php endif;?>'), $content); |
| 1666 | 1666 | ob_start(); |
| 1667 | - $content = eval('?>' . $content); |
|
| 1667 | + $content = eval('?>'.$content); |
|
| 1668 | 1668 | $content = ob_get_clean(); |
| 1669 | 1669 | $content = str_replace(array("{$sp}b", "{$sp}p", "{$sp}s", "{$sp}e"), array('<?php', '<?=', '<?', '?>'), $content); |
| 1670 | 1670 | |
@@ -1789,7 +1789,7 @@ discard block |
||
| 1789 | 1789 | $matches = $this->getTagsFromContent($content, $left, $right); |
| 1790 | 1790 | if (!empty($matches)) { |
| 1791 | 1791 | foreach ($matches[0] as $i => $v) { |
| 1792 | - $addBreakMatches[$i] = $v . "\n"; |
|
| 1792 | + $addBreakMatches[$i] = $v."\n"; |
|
| 1793 | 1793 | } |
| 1794 | 1794 | $content = str_replace($addBreakMatches, '', $content); |
| 1795 | 1795 | if (strpos($content, $left) !== false) { |
@@ -1822,8 +1822,8 @@ discard block |
||
| 1822 | 1822 | $s = &$matches[0][$i]; |
| 1823 | 1823 | if (strpos($content, $s) !== false) { |
| 1824 | 1824 | $content = str_replace($s, $v, $content); |
| 1825 | - } elseif($this->debug) { |
|
| 1826 | - $this->addLog('ignoreCommentedTagsContent parse error', $_SERVER['REQUEST_URI'] . $s, 2); |
|
| 1825 | + } elseif ($this->debug) { |
|
| 1826 | + $this->addLog('ignoreCommentedTagsContent parse error', $_SERVER['REQUEST_URI'].$s, 2); |
|
| 1827 | 1827 | } |
| 1828 | 1828 | } |
| 1829 | 1829 | return $content; |
@@ -1887,7 +1887,7 @@ discard block |
||
| 1887 | 1887 | $msg = ($msg === false) ? 'ob_get_contents() error' : $msg; |
| 1888 | 1888 | $this->messageQuit('PHP Parse Error', '', true, $error_info['type'], $error_info['file'], 'Plugin', $error_info['message'], $error_info['line'], $msg); |
| 1889 | 1889 | if ($this->isBackend()) { |
| 1890 | - $this->event->alert('An error occurred while loading. Please see the event log for more information.<p>' . $msg . '</p>'); |
|
| 1890 | + $this->event->alert('An error occurred while loading. Please see the event log for more information.<p>'.$msg.'</p>'); |
|
| 1891 | 1891 | } |
| 1892 | 1892 | } |
| 1893 | 1893 | } else { |
@@ -1933,7 +1933,7 @@ discard block |
||
| 1933 | 1933 | $echo = ($echo === false) ? 'ob_get_contents() error' : $echo; |
| 1934 | 1934 | $this->messageQuit('PHP Parse Error', '', true, $error_info['type'], $error_info['file'], 'Snippet', $error_info['message'], $error_info['line'], $echo); |
| 1935 | 1935 | if ($this->isBackend()) { |
| 1936 | - $this->event->alert('An error occurred while loading. Please see the event log for more information<p>' . $echo . $return . '</p>'); |
|
| 1936 | + $this->event->alert('An error occurred while loading. Please see the event log for more information<p>'.$echo.$return.'</p>'); |
|
| 1937 | 1937 | } |
| 1938 | 1938 | } |
| 1939 | 1939 | } |
@@ -1941,7 +1941,7 @@ discard block |
||
| 1941 | 1941 | if (is_array($return) || is_object($return)) { |
| 1942 | 1942 | return $return; |
| 1943 | 1943 | } else { |
| 1944 | - return $echo . $return; |
|
| 1944 | + return $echo.$return; |
|
| 1945 | 1945 | } |
| 1946 | 1946 | } |
| 1947 | 1947 | |
@@ -1979,8 +1979,8 @@ discard block |
||
| 1979 | 1979 | } |
| 1980 | 1980 | if (strpos($content, $s) !== false) { |
| 1981 | 1981 | $content = str_replace($s, $value, $content); |
| 1982 | - } elseif($this->debug) { |
|
| 1983 | - $this->addLog('evalSnippetsSGVar parse error', $_SERVER['REQUEST_URI'] . $s, 2); |
|
| 1982 | + } elseif ($this->debug) { |
|
| 1983 | + $this->addLog('evalSnippetsSGVar parse error', $_SERVER['REQUEST_URI'].$s, 2); |
|
| 1984 | 1984 | } |
| 1985 | 1985 | continue; |
| 1986 | 1986 | } |
@@ -1991,8 +1991,8 @@ discard block |
||
| 1991 | 1991 | |
| 1992 | 1992 | if (strpos($content, $s) !== false) { |
| 1993 | 1993 | $content = str_replace($s, $value, $content); |
| 1994 | - } elseif($this->debug) { |
|
| 1995 | - $this->addLog('evalSnippets parse error', $_SERVER['REQUEST_URI'] . $s, 2); |
|
| 1994 | + } elseif ($this->debug) { |
|
| 1995 | + $this->addLog('evalSnippets parse error', $_SERVER['REQUEST_URI'].$s, 2); |
|
| 1996 | 1996 | } |
| 1997 | 1997 | } |
| 1998 | 1998 | |
@@ -2083,7 +2083,7 @@ discard block |
||
| 2083 | 2083 | $eventtime = sprintf('%2.2f ms', $eventtime * 1000); |
| 2084 | 2084 | $code = str_replace("\t", ' ', $this->htmlspecialchars($value)); |
| 2085 | 2085 | $piece = str_replace("\t", ' ', $this->htmlspecialchars($piece)); |
| 2086 | - $print_r_params = str_replace("\t", ' ', $this->htmlspecialchars('$modx->event->params = ' . print_r($params, true))); |
|
| 2086 | + $print_r_params = str_replace("\t", ' ', $this->htmlspecialchars('$modx->event->params = '.print_r($params, true))); |
|
| 2087 | 2087 | $this->snippetsCode .= sprintf('<fieldset style="margin:1em;"><legend><b>%s</b>(%s)</legend><pre style="white-space: pre-wrap;background-color:#fff;width:90%%;">[[%s]]</pre><pre style="white-space: pre-wrap;background-color:#fff;width:90%%;">%s</pre><pre style="white-space: pre-wrap;background-color:#fff;width:90%%;">%s</pre></fieldset>', $snippetObject['name'], $eventtime, $piece, $print_r_params, $code); |
| 2088 | 2088 | $this->snippetsTime[] = array('sname' => $key, 'time' => $eventtime); |
| 2089 | 2089 | } |
@@ -2327,7 +2327,7 @@ discard block |
||
| 2327 | 2327 | $rs = $this->db->select('name,snippet,properties', '[+prefix+]site_snippets', $where); |
| 2328 | 2328 | $count = $this->db->getRecordCount($rs); |
| 2329 | 2329 | if (1 < $count) { |
| 2330 | - exit('Error $modx->_getSnippetObject()' . $snip_name); |
|
| 2330 | + exit('Error $modx->_getSnippetObject()'.$snip_name); |
|
| 2331 | 2331 | } |
| 2332 | 2332 | if ($count) { |
| 2333 | 2333 | $row = $this->db->getRow($rs); |
@@ -2353,7 +2353,7 @@ discard block |
||
| 2353 | 2353 | public function toAlias($text) |
| 2354 | 2354 | { |
| 2355 | 2355 | $suff = $this->config['friendly_url_suffix']; |
| 2356 | - return str_replace(array('.xml' . $suff, '.rss' . $suff, '.js' . $suff, '.css' . $suff, '.txt' . $suff, '.json' . $suff, '.pdf' . $suff), array('.xml', '.rss', '.js', '.css', '.txt', '.json', '.pdf'), $text); |
|
| 2356 | + return str_replace(array('.xml'.$suff, '.rss'.$suff, '.js'.$suff, '.css'.$suff, '.txt'.$suff, '.json'.$suff, '.pdf'.$suff), array('.xml', '.rss', '.js', '.css', '.txt', '.json', '.pdf'), $text); |
|
| 2357 | 2357 | } |
| 2358 | 2358 | |
| 2359 | 2359 | /** |
@@ -2385,7 +2385,7 @@ discard block |
||
| 2385 | 2385 | $suff = '/'; |
| 2386 | 2386 | } |
| 2387 | 2387 | |
| 2388 | - $url = ($dir != '' ? $dir . '/' : '') . $pre . $alias . $suff; |
|
| 2388 | + $url = ($dir != '' ? $dir.'/' : '').$pre.$alias.$suff; |
|
| 2389 | 2389 | } |
| 2390 | 2390 | |
| 2391 | 2391 | $evtOut = $this->invokeEvent('OnMakeDocUrl', array( |
@@ -2422,7 +2422,7 @@ discard block |
||
| 2422 | 2422 | preg_match_all('!\[\~([0-9]+)\~\]!ise', $documentSource, $match); |
| 2423 | 2423 | $ids = implode(',', array_unique($match['1'])); |
| 2424 | 2424 | if ($ids) { |
| 2425 | - $res = $this->db->select("id,alias,isfolder,parent,alias_visible", $this->getFullTableName('site_content'), "id IN (" . $ids . ") AND isfolder = '0'"); |
|
| 2425 | + $res = $this->db->select("id,alias,isfolder,parent,alias_visible", $this->getFullTableName('site_content'), "id IN (".$ids.") AND isfolder = '0'"); |
|
| 2426 | 2426 | while ($row = $this->db->getRow($res)) { |
| 2427 | 2427 | if ($this->config['use_alias_path'] == '1' && $row['parent'] != 0) { |
| 2428 | 2428 | $parent = $row['parent']; |
@@ -2433,7 +2433,7 @@ discard block |
||
| 2433 | 2433 | $parent = $this->aliasListing[$parent]['parent']; |
| 2434 | 2434 | } |
| 2435 | 2435 | |
| 2436 | - $aliases[$row['id']] = $path . '/' . $row['alias']; |
|
| 2436 | + $aliases[$row['id']] = $path.'/'.$row['alias']; |
|
| 2437 | 2437 | } else { |
| 2438 | 2438 | $aliases[$row['id']] = $row['alias']; |
| 2439 | 2439 | } |
@@ -2445,7 +2445,7 @@ discard block |
||
| 2445 | 2445 | $isfriendly = ($this->config['friendly_alias_urls'] == 1 ? 1 : 0); |
| 2446 | 2446 | $pref = $this->config['friendly_url_prefix']; |
| 2447 | 2447 | $suff = $this->config['friendly_url_suffix']; |
| 2448 | - $documentSource = preg_replace_callback($in, function ($m) use ($aliases, $isfolder, $isfriendly, $pref, $suff) { |
|
| 2448 | + $documentSource = preg_replace_callback($in, function($m) use ($aliases, $isfolder, $isfriendly, $pref, $suff) { |
|
| 2449 | 2449 | global $modx; |
| 2450 | 2450 | $thealias = $aliases[$m[1]]; |
| 2451 | 2451 | $thefolder = $isfolder[$m[1]]; |
@@ -2461,7 +2461,7 @@ discard block |
||
| 2461 | 2461 | |
| 2462 | 2462 | } else { |
| 2463 | 2463 | $in = '!\[\~([0-9]+)\~\]!is'; |
| 2464 | - $out = "index.php?id=" . '\1'; |
|
| 2464 | + $out = "index.php?id=".'\1'; |
|
| 2465 | 2465 | $documentSource = preg_replace($in, $out, $documentSource); |
| 2466 | 2466 | } |
| 2467 | 2467 | |
@@ -2482,7 +2482,7 @@ discard block |
||
| 2482 | 2482 | $scheme = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http'; |
| 2483 | 2483 | $len_base_url = strlen($this->config['base_url']); |
| 2484 | 2484 | |
| 2485 | - $url_path = $q;//LANG |
|
| 2485 | + $url_path = $q; //LANG |
|
| 2486 | 2486 | |
| 2487 | 2487 | if (substr($url_path, 0, $len_base_url) === $this->config['base_url']) { |
| 2488 | 2488 | $url_path = substr($url_path, $len_base_url); |
@@ -2494,7 +2494,7 @@ discard block |
||
| 2494 | 2494 | $strictURL = substr($strictURL, $len_base_url); |
| 2495 | 2495 | } |
| 2496 | 2496 | $http_host = $_SERVER['HTTP_HOST']; |
| 2497 | - $requestedURL = "{$scheme}://{$http_host}" . '/' . $q; //LANG |
|
| 2497 | + $requestedURL = "{$scheme}://{$http_host}".'/'.$q; //LANG |
|
| 2498 | 2498 | |
| 2499 | 2499 | $site_url = $this->config['site_url']; |
| 2500 | 2500 | |
@@ -2510,7 +2510,7 @@ discard block |
||
| 2510 | 2510 | } |
| 2511 | 2511 | if ($this->config['base_url'] != $_SERVER['REQUEST_URI']) { |
| 2512 | 2512 | if (empty($_POST)) { |
| 2513 | - if (($this->config['base_url'] . '?' . $qstring) != $_SERVER['REQUEST_URI']) { |
|
| 2513 | + if (($this->config['base_url'].'?'.$qstring) != $_SERVER['REQUEST_URI']) { |
|
| 2514 | 2514 | $this->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.0 301 Moved Permanently'); |
| 2515 | 2515 | exit(0); |
| 2516 | 2516 | } |
@@ -2573,7 +2573,7 @@ discard block |
||
| 2573 | 2573 | $docgrp = implode(",", $docgrp); |
| 2574 | 2574 | } |
| 2575 | 2575 | // get document |
| 2576 | - $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)"); |
|
| 2576 | + $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='".$_SESSION['mgrRole']."' OR sc.privatemgr=0").(!$docgrp ? "" : " OR dg.document_group IN ($docgrp)"); |
|
| 2577 | 2577 | $rs = $this->db->select('sc.*', "{$tblsc} sc |
| 2578 | 2578 | LEFT JOIN {$tbldg} dg ON dg.document = sc.id", "sc.{$method} = '{$identifier}' AND ({$access})", "", 1); |
| 2579 | 2579 | if ($this->db->getRecordCount($rs) < 1) { |
@@ -2609,9 +2609,9 @@ discard block |
||
| 2609 | 2609 | } |
| 2610 | 2610 | if ($documentObject['template']) { |
| 2611 | 2611 | // load TVs and merge with document - Orig by Apodigm - Docvars |
| 2612 | - $rs = $this->db->select("tv.*, IF(tvc.value!='',tvc.value,tv.default_text) as value", $this->getFullTableName("site_tmplvars") . " tv |
|
| 2613 | - INNER JOIN " . $this->getFullTableName("site_tmplvar_templates") . " tvtpl ON tvtpl.tmplvarid = tv.id |
|
| 2614 | - LEFT JOIN " . $this->getFullTableName("site_tmplvar_contentvalues") . " tvc ON tvc.tmplvarid=tv.id AND tvc.contentid = '{$documentObject['id']}'", "tvtpl.templateid = '{$documentObject['template']}'"); |
|
| 2612 | + $rs = $this->db->select("tv.*, IF(tvc.value!='',tvc.value,tv.default_text) as value", $this->getFullTableName("site_tmplvars")." tv |
|
| 2613 | + INNER JOIN " . $this->getFullTableName("site_tmplvar_templates")." tvtpl ON tvtpl.tmplvarid = tv.id |
|
| 2614 | + LEFT JOIN " . $this->getFullTableName("site_tmplvar_contentvalues")." tvc ON tvc.tmplvarid=tv.id AND tvc.contentid = '{$documentObject['id']}'", "tvtpl.templateid = '{$documentObject['template']}'"); |
|
| 2615 | 2615 | $tmplvars = array(); |
| 2616 | 2616 | while ($row = $this->db->getRow($rs)) { |
| 2617 | 2617 | $tmplvars[$row['name']] = array( |
@@ -2657,7 +2657,7 @@ discard block |
||
| 2657 | 2657 | $st = md5($source); |
| 2658 | 2658 | } |
| 2659 | 2659 | if ($this->dumpSnippets == 1) { |
| 2660 | - $this->snippetsCode .= "<fieldset><legend><b style='color: #821517;'>PARSE PASS " . ($i + 1) . "</b></legend><p>The following snippets (if any) were parsed during this pass.</p>"; |
|
| 2660 | + $this->snippetsCode .= "<fieldset><legend><b style='color: #821517;'>PARSE PASS ".($i + 1)."</b></legend><p>The following snippets (if any) were parsed during this pass.</p>"; |
|
| 2661 | 2661 | } |
| 2662 | 2662 | |
| 2663 | 2663 | // invoke OnParseDocument event |
@@ -2743,7 +2743,7 @@ discard block |
||
| 2743 | 2743 | |
| 2744 | 2744 | // Check use_alias_path and check if $this->virtualDir is set to anything, then parse the path |
| 2745 | 2745 | if ($this->config['use_alias_path'] == 1) { |
| 2746 | - $alias = (strlen($this->virtualDir) > 0 ? $this->virtualDir . '/' : '') . $this->documentIdentifier; |
|
| 2746 | + $alias = (strlen($this->virtualDir) > 0 ? $this->virtualDir.'/' : '').$this->documentIdentifier; |
|
| 2747 | 2747 | if (isset($this->documentListing[$alias])) { |
| 2748 | 2748 | $this->documentIdentifier = $this->documentListing[$alias]; |
| 2749 | 2749 | } else { |
@@ -2804,7 +2804,7 @@ discard block |
||
| 2804 | 2804 | } else { |
| 2805 | 2805 | $docAlias = $this->db->escape($this->documentIdentifier); |
| 2806 | 2806 | $rs = $this->db->select('id', $this->getFullTableName('site_content'), "deleted=0 and alias='{$docAlias}'"); |
| 2807 | - $this->documentIdentifier = (int)$this->db->getValue($rs); |
|
| 2807 | + $this->documentIdentifier = (int) $this->db->getValue($rs); |
|
| 2808 | 2808 | } |
| 2809 | 2809 | } |
| 2810 | 2810 | $this->documentMethod = 'id'; |
@@ -2857,7 +2857,7 @@ discard block |
||
| 2857 | 2857 | $_REQUEST[$n] = $_GET[$n] = $v; |
| 2858 | 2858 | } |
| 2859 | 2859 | } |
| 2860 | - $_SERVER['PHP_SELF'] = $this->config['base_url'] . $qp['path']; |
|
| 2860 | + $_SERVER['PHP_SELF'] = $this->config['base_url'].$qp['path']; |
|
| 2861 | 2861 | $this->q = $qp['path']; |
| 2862 | 2862 | return $qp['path']; |
| 2863 | 2863 | } |
@@ -2951,7 +2951,7 @@ discard block |
||
| 2951 | 2951 | $this->sendErrorPage(); |
| 2952 | 2952 | } else { |
| 2953 | 2953 | // Inculde the necessary files to check document permissions |
| 2954 | - include_once(MODX_MANAGER_PATH . 'processors/user_documents_permissions.class.php'); |
|
| 2954 | + include_once(MODX_MANAGER_PATH.'processors/user_documents_permissions.class.php'); |
|
| 2955 | 2955 | $udperms = new udperms(); |
| 2956 | 2956 | $udperms->user = $this->getLoginUserID(); |
| 2957 | 2957 | $udperms->document = $this->documentIdentifier; |
@@ -3005,7 +3005,7 @@ discard block |
||
| 3005 | 3005 | while ($id && $height--) { |
| 3006 | 3006 | $thisid = $id; |
| 3007 | 3007 | if ($this->config['aliaslistingfolder'] == 1) { |
| 3008 | - $id = isset($this->aliasListing[$id]['parent']) ? $this->aliasListing[$id]['parent'] : $this->db->getValue("SELECT `parent` FROM " . $this->getFullTableName("site_content") . " WHERE `id` = '{$id}' LIMIT 0,1"); |
|
| 3008 | + $id = isset($this->aliasListing[$id]['parent']) ? $this->aliasListing[$id]['parent'] : $this->db->getValue("SELECT `parent` FROM ".$this->getFullTableName("site_content")." WHERE `id` = '{$id}' LIMIT 0,1"); |
|
| 3009 | 3009 | if (!$id || $id == '0') { |
| 3010 | 3010 | break; |
| 3011 | 3011 | } |
@@ -3056,15 +3056,15 @@ discard block |
||
| 3056 | 3056 | |
| 3057 | 3057 | if ($this->config['aliaslistingfolder'] == 1) { |
| 3058 | 3058 | |
| 3059 | - $res = $this->db->select("id,alias,isfolder,parent", $this->getFullTableName('site_content'), "parent IN (" . $id . ") AND deleted = '0'"); |
|
| 3059 | + $res = $this->db->select("id,alias,isfolder,parent", $this->getFullTableName('site_content'), "parent IN (".$id.") AND deleted = '0'"); |
|
| 3060 | 3060 | $idx = array(); |
| 3061 | 3061 | while ($row = $this->db->getRow($res)) { |
| 3062 | 3062 | $pAlias = ''; |
| 3063 | 3063 | if (isset($this->aliasListing[$row['parent']])) { |
| 3064 | - $pAlias .= !empty($this->aliasListing[$row['parent']]['path']) ? $this->aliasListing[$row['parent']]['path'] . '/' : ''; |
|
| 3065 | - $pAlias .= !empty($this->aliasListing[$row['parent']]['alias']) ? $this->aliasListing[$row['parent']]['alias'] . '/' : ''; |
|
| 3064 | + $pAlias .= !empty($this->aliasListing[$row['parent']]['path']) ? $this->aliasListing[$row['parent']]['path'].'/' : ''; |
|
| 3065 | + $pAlias .= !empty($this->aliasListing[$row['parent']]['alias']) ? $this->aliasListing[$row['parent']]['alias'].'/' : ''; |
|
| 3066 | 3066 | }; |
| 3067 | - $children[$pAlias . $row['alias']] = $row['id']; |
|
| 3067 | + $children[$pAlias.$row['alias']] = $row['id']; |
|
| 3068 | 3068 | if ($row['isfolder'] == 1) { |
| 3069 | 3069 | $idx[] = $row['id']; |
| 3070 | 3070 | } |
@@ -3096,7 +3096,7 @@ discard block |
||
| 3096 | 3096 | $depth--; |
| 3097 | 3097 | |
| 3098 | 3098 | foreach ($documentMap_cache[$id] as $childId) { |
| 3099 | - $pkey = (strlen($this->aliasListing[$childId]['path']) ? "{$this->aliasListing[$childId]['path']}/" : '') . $this->aliasListing[$childId]['alias']; |
|
| 3099 | + $pkey = (strlen($this->aliasListing[$childId]['path']) ? "{$this->aliasListing[$childId]['path']}/" : '').$this->aliasListing[$childId]['alias']; |
|
| 3100 | 3100 | if (!strlen($pkey)) { |
| 3101 | 3101 | $pkey = "{$childId}"; |
| 3102 | 3102 | } |
@@ -3125,7 +3125,7 @@ discard block |
||
| 3125 | 3125 | if (substr(strtolower($url), 0, 11) == "javascript:") { |
| 3126 | 3126 | $fnc = substr($url, 11); |
| 3127 | 3127 | } elseif ($url) { |
| 3128 | - $fnc = "window.location.href='" . addslashes($url) . "';"; |
|
| 3128 | + $fnc = "window.location.href='".addslashes($url)."';"; |
|
| 3129 | 3129 | } else { |
| 3130 | 3130 | $fnc = "history.back(-1);"; |
| 3131 | 3131 | } |
@@ -3134,7 +3134,7 @@ discard block |
||
| 3134 | 3134 | <meta http-equiv=\"Content-Type\" content=\"text/html; charset={$modx_manager_charset};\"> |
| 3135 | 3135 | <script> |
| 3136 | 3136 | function __alertQuit() { |
| 3137 | - alert('" . addslashes($msg) . "'); |
|
| 3137 | + alert('".addslashes($msg)."'); |
|
| 3138 | 3138 | {$fnc} |
| 3139 | 3139 | } |
| 3140 | 3140 | window.setTimeout('__alertQuit();',100); |
@@ -3158,7 +3158,7 @@ discard block |
||
| 3158 | 3158 | if ($pms) { |
| 3159 | 3159 | $state = ($pms[$pm] == 1); |
| 3160 | 3160 | } |
| 3161 | - return (int)$state; |
|
| 3161 | + return (int) $state; |
|
| 3162 | 3162 | } |
| 3163 | 3163 | |
| 3164 | 3164 | /** |
@@ -3171,8 +3171,8 @@ discard block |
||
| 3171 | 3171 | */ |
| 3172 | 3172 | public function elementIsLocked($type, $id, $includeThisUser = false) |
| 3173 | 3173 | { |
| 3174 | - $id = (int)$id; |
|
| 3175 | - $type = (int)$type; |
|
| 3174 | + $id = (int) $id; |
|
| 3175 | + $type = (int) $type; |
|
| 3176 | 3176 | if (!$type || !$id) { |
| 3177 | 3177 | return null; |
| 3178 | 3178 | } |
@@ -3222,7 +3222,7 @@ discard block |
||
| 3222 | 3222 | return $lockedElements; |
| 3223 | 3223 | } |
| 3224 | 3224 | |
| 3225 | - $type = (int)$type; |
|
| 3225 | + $type = (int) $type; |
|
| 3226 | 3226 | if (isset($lockedElements[$type])) { |
| 3227 | 3227 | return $lockedElements[$type]; |
| 3228 | 3228 | } else { |
@@ -3239,7 +3239,7 @@ discard block |
||
| 3239 | 3239 | $this->lockedElements = array(); |
| 3240 | 3240 | $this->cleanupExpiredLocks(); |
| 3241 | 3241 | |
| 3242 | - $rs = $this->db->select('sid,internalKey,elementType,elementId,lasthit,username', $this->getFullTableName('active_user_locks') . " ul |
|
| 3242 | + $rs = $this->db->select('sid,internalKey,elementType,elementId,lasthit,username', $this->getFullTableName('active_user_locks')." ul |
|
| 3243 | 3243 | LEFT JOIN {$this->getFullTableName('manager_users')} mu on ul.internalKey = mu.id"); |
| 3244 | 3244 | while ($row = $this->db->getRow($rs)) { |
| 3245 | 3245 | $this->lockedElements[$row['elementType']][$row['elementId']] = array( |
@@ -3262,7 +3262,7 @@ discard block |
||
| 3262 | 3262 | public function cleanupExpiredLocks() |
| 3263 | 3263 | { |
| 3264 | 3264 | // Clean-up active_user_sessions first |
| 3265 | - $timeout = (int)$this->config['session_timeout'] < 2 ? 120 : $this->config['session_timeout'] * 60; // session.js pings every 10min, updateMail() in mainMenu pings every minute, so 2min is minimum |
|
| 3265 | + $timeout = (int) $this->config['session_timeout'] < 2 ? 120 : $this->config['session_timeout'] * 60; // session.js pings every 10min, updateMail() in mainMenu pings every minute, so 2min is minimum |
|
| 3266 | 3266 | $validSessionTimeLimit = $this->time - $timeout; |
| 3267 | 3267 | $this->db->delete($this->getFullTableName('active_user_sessions'), "lasthit < {$validSessionTimeLimit}"); |
| 3268 | 3268 | |
@@ -3275,7 +3275,7 @@ discard block |
||
| 3275 | 3275 | foreach ($rs as $row) { |
| 3276 | 3276 | $userSids[] = $row['sid']; |
| 3277 | 3277 | } |
| 3278 | - $userSids = "'" . implode("','", $userSids) . "'"; |
|
| 3278 | + $userSids = "'".implode("','", $userSids)."'"; |
|
| 3279 | 3279 | $this->db->delete($this->getFullTableName('active_user_locks'), "sid NOT IN({$userSids})"); |
| 3280 | 3280 | } else { |
| 3281 | 3281 | $this->db->delete($this->getFullTableName('active_user_locks')); |
@@ -3359,8 +3359,8 @@ discard block |
||
| 3359 | 3359 | public function lockElement($type, $id) |
| 3360 | 3360 | { |
| 3361 | 3361 | $userId = $this->isBackend() && $_SESSION['mgrInternalKey'] ? $_SESSION['mgrInternalKey'] : 0; |
| 3362 | - $type = (int)$type; |
|
| 3363 | - $id = (int)$id; |
|
| 3362 | + $type = (int) $type; |
|
| 3363 | + $id = (int) $id; |
|
| 3364 | 3364 | if (!$type || !$id || !$userId) { |
| 3365 | 3365 | return false; |
| 3366 | 3366 | } |
@@ -3381,8 +3381,8 @@ discard block |
||
| 3381 | 3381 | public function unlockElement($type, $id, $includeAllUsers = false) |
| 3382 | 3382 | { |
| 3383 | 3383 | $userId = $this->isBackend() && $_SESSION['mgrInternalKey'] ? $_SESSION['mgrInternalKey'] : 0; |
| 3384 | - $type = (int)$type; |
|
| 3385 | - $id = (int)$id; |
|
| 3384 | + $type = (int) $type; |
|
| 3385 | + $id = (int) $id; |
|
| 3386 | 3386 | if (!$type || !$id) { |
| 3387 | 3387 | return false; |
| 3388 | 3388 | } |
@@ -3449,8 +3449,8 @@ discard block |
||
| 3449 | 3449 | } |
| 3450 | 3450 | |
| 3451 | 3451 | $usertype = $this->isFrontend() ? 1 : 0; |
| 3452 | - $evtid = (int)$evtid; |
|
| 3453 | - $type = (int)$type; |
|
| 3452 | + $evtid = (int) $evtid; |
|
| 3453 | + $type = (int) $type; |
|
| 3454 | 3454 | |
| 3455 | 3455 | // Types: 1 = information, 2 = warning, 3 = error |
| 3456 | 3456 | if ($type < 1) { |
@@ -3472,8 +3472,8 @@ discard block |
||
| 3472 | 3472 | if (isset($this->config['send_errormail']) && $this->config['send_errormail'] !== '0') { |
| 3473 | 3473 | if ($this->config['send_errormail'] <= $type) { |
| 3474 | 3474 | $this->sendmail(array( |
| 3475 | - 'subject' => 'MODX System Error on ' . $this->config['site_name'], |
|
| 3476 | - 'body' => 'Source: ' . $source . ' - The details of the error could be seen in the MODX system events log.', |
|
| 3475 | + 'subject' => 'MODX System Error on '.$this->config['site_name'], |
|
| 3476 | + 'body' => 'Source: '.$source.' - The details of the error could be seen in the MODX system events log.', |
|
| 3477 | 3477 | 'type' => 'text' |
| 3478 | 3478 | )); |
| 3479 | 3479 | } |
@@ -3521,7 +3521,7 @@ discard block |
||
| 3521 | 3521 | $p['fromname'] = $userinfo['username']; |
| 3522 | 3522 | } |
| 3523 | 3523 | if ($msg === '' && !isset($p['body'])) { |
| 3524 | - $p['body'] = $_SERVER['REQUEST_URI'] . "\n" . $_SERVER['HTTP_USER_AGENT'] . "\n" . $_SERVER['HTTP_REFERER']; |
|
| 3524 | + $p['body'] = $_SERVER['REQUEST_URI']."\n".$_SERVER['HTTP_USER_AGENT']."\n".$_SERVER['HTTP_REFERER']; |
|
| 3525 | 3525 | } elseif (is_string($msg) && 0 < strlen($msg)) { |
| 3526 | 3526 | $p['body'] = $msg; |
| 3527 | 3527 | } |
@@ -3561,8 +3561,8 @@ discard block |
||
| 3561 | 3561 | $files = array(); |
| 3562 | 3562 | } |
| 3563 | 3563 | foreach ($files as $f) { |
| 3564 | - if (file_exists(MODX_BASE_PATH . $f) && is_file(MODX_BASE_PATH . $f) && is_readable(MODX_BASE_PATH . $f)) { |
|
| 3565 | - $this->mail->AddAttachment(MODX_BASE_PATH . $f); |
|
| 3564 | + if (file_exists(MODX_BASE_PATH.$f) && is_file(MODX_BASE_PATH.$f) && is_readable(MODX_BASE_PATH.$f)) { |
|
| 3565 | + $this->mail->AddAttachment(MODX_BASE_PATH.$f); |
|
| 3566 | 3566 | } |
| 3567 | 3567 | } |
| 3568 | 3568 | $rs = $this->mail->send(); |
@@ -3607,7 +3607,7 @@ discard block |
||
| 3607 | 3607 | */ |
| 3608 | 3608 | public function isFrontend() |
| 3609 | 3609 | { |
| 3610 | - return ! $this->isBackend(); |
|
| 3610 | + return !$this->isBackend(); |
|
| 3611 | 3611 | } |
| 3612 | 3612 | |
| 3613 | 3613 | /** |
@@ -3632,14 +3632,14 @@ discard block |
||
| 3632 | 3632 | $tblsc = $this->getFullTableName("site_content"); |
| 3633 | 3633 | $tbldg = $this->getFullTableName("document_groups"); |
| 3634 | 3634 | // modify field names to use sc. table reference |
| 3635 | - $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields)))); |
|
| 3636 | - $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort)))); |
|
| 3635 | + $fields = 'sc.'.implode(',sc.', array_filter(array_map('trim', explode(',', $fields)))); |
|
| 3636 | + $sort = 'sc.'.implode(',sc.', array_filter(array_map('trim', explode(',', $sort)))); |
|
| 3637 | 3637 | // get document groups for current user |
| 3638 | 3638 | if ($docgrp = $this->getUserDocGroups()) { |
| 3639 | 3639 | $docgrp = implode(",", $docgrp); |
| 3640 | 3640 | } |
| 3641 | 3641 | // build query |
| 3642 | - $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)"); |
|
| 3642 | + $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='".$_SESSION['mgrRole']."' OR sc.privatemgr=0").(!$docgrp ? "" : " OR dg.document_group IN ($docgrp)"); |
|
| 3643 | 3643 | $result = $this->db->select("DISTINCT {$fields}", "{$tblsc} sc |
| 3644 | 3644 | LEFT JOIN {$tbldg} dg on dg.document = sc.id", "sc.parent = '{$id}' AND ({$access}) GROUP BY sc.id", "{$sort} {$dir}"); |
| 3645 | 3645 | $resourceArray = $this->db->makeArray($result); |
@@ -3669,14 +3669,14 @@ discard block |
||
| 3669 | 3669 | $tbldg = $this->getFullTableName("document_groups"); |
| 3670 | 3670 | |
| 3671 | 3671 | // modify field names to use sc. table reference |
| 3672 | - $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields)))); |
|
| 3673 | - $sort = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort)))); |
|
| 3672 | + $fields = 'sc.'.implode(',sc.', array_filter(array_map('trim', explode(',', $fields)))); |
|
| 3673 | + $sort = 'sc.'.implode(',sc.', array_filter(array_map('trim', explode(',', $sort)))); |
|
| 3674 | 3674 | // get document groups for current user |
| 3675 | 3675 | if ($docgrp = $this->getUserDocGroups()) { |
| 3676 | 3676 | $docgrp = implode(",", $docgrp); |
| 3677 | 3677 | } |
| 3678 | 3678 | // build query |
| 3679 | - $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)"); |
|
| 3679 | + $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='".$_SESSION['mgrRole']."' OR sc.privatemgr=0").(!$docgrp ? "" : " OR dg.document_group IN ($docgrp)"); |
|
| 3680 | 3680 | $result = $this->db->select("DISTINCT {$fields}", "{$tblsc} sc |
| 3681 | 3681 | LEFT JOIN {$tbldg} dg on dg.document = sc.id", "sc.parent = '{$id}' AND sc.published=1 AND sc.deleted=0 AND ({$access}) GROUP BY sc.id", "{$sort} {$dir}"); |
| 3682 | 3682 | $resourceArray = $this->db->makeArray($result); |
@@ -3711,16 +3711,16 @@ discard block |
||
| 3711 | 3711 | return $this->tmpCache[__FUNCTION__][$cacheKey]; |
| 3712 | 3712 | } |
| 3713 | 3713 | |
| 3714 | - $published = ($published !== 'all') ? 'AND sc.published = ' . $published : ''; |
|
| 3715 | - $deleted = ($deleted !== 'all') ? 'AND sc.deleted = ' . $deleted : ''; |
|
| 3714 | + $published = ($published !== 'all') ? 'AND sc.published = '.$published : ''; |
|
| 3715 | + $deleted = ($deleted !== 'all') ? 'AND sc.deleted = '.$deleted : ''; |
|
| 3716 | 3716 | |
| 3717 | 3717 | if ($where != '') { |
| 3718 | - $where = 'AND ' . $where; |
|
| 3718 | + $where = 'AND '.$where; |
|
| 3719 | 3719 | } |
| 3720 | 3720 | |
| 3721 | 3721 | // modify field names to use sc. table reference |
| 3722 | - $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields)))); |
|
| 3723 | - $sort = ($sort == '') ? '' : 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort)))); |
|
| 3722 | + $fields = 'sc.'.implode(',sc.', array_filter(array_map('trim', explode(',', $fields)))); |
|
| 3723 | + $sort = ($sort == '') ? '' : 'sc.'.implode(',sc.', array_filter(array_map('trim', explode(',', $sort)))); |
|
| 3724 | 3724 | |
| 3725 | 3725 | // get document groups for current user |
| 3726 | 3726 | if ($docgrp = $this->getUserDocGroups()) { |
@@ -3728,7 +3728,7 @@ discard block |
||
| 3728 | 3728 | } |
| 3729 | 3729 | |
| 3730 | 3730 | // build query |
| 3731 | - $access = ($this->isFrontend() ? 'sc.privateweb=0' : '1="' . $_SESSION['mgrRole'] . '" OR sc.privatemgr=0') . (!$docgrp ? '' : ' OR dg.document_group IN (' . $docgrp . ')'); |
|
| 3731 | + $access = ($this->isFrontend() ? 'sc.privateweb=0' : '1="'.$_SESSION['mgrRole'].'" OR sc.privatemgr=0').(!$docgrp ? '' : ' OR dg.document_group IN ('.$docgrp.')'); |
|
| 3732 | 3732 | |
| 3733 | 3733 | $tblsc = $this->getFullTableName('site_content'); |
| 3734 | 3734 | $tbldg = $this->getFullTableName('document_groups'); |
@@ -3780,10 +3780,10 @@ discard block |
||
| 3780 | 3780 | return false; |
| 3781 | 3781 | } else { |
| 3782 | 3782 | // modify field names to use sc. table reference |
| 3783 | - $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields)))); |
|
| 3784 | - $sort = ($sort == '') ? '' : 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $sort)))); |
|
| 3783 | + $fields = 'sc.'.implode(',sc.', array_filter(array_map('trim', explode(',', $fields)))); |
|
| 3784 | + $sort = ($sort == '') ? '' : 'sc.'.implode(',sc.', array_filter(array_map('trim', explode(',', $sort)))); |
|
| 3785 | 3785 | if ($where != '') { |
| 3786 | - $where = 'AND ' . $where; |
|
| 3786 | + $where = 'AND '.$where; |
|
| 3787 | 3787 | } |
| 3788 | 3788 | |
| 3789 | 3789 | $published = ($published !== 'all') ? "AND sc.published = '{$published}'" : ''; |
@@ -3794,13 +3794,13 @@ discard block |
||
| 3794 | 3794 | $docgrp = implode(',', $docgrp); |
| 3795 | 3795 | } |
| 3796 | 3796 | |
| 3797 | - $access = ($this->isFrontend() ? 'sc.privateweb=0' : '1="' . $_SESSION['mgrRole'] . '" OR sc.privatemgr=0') . (!$docgrp ? '' : ' OR dg.document_group IN (' . $docgrp . ')'); |
|
| 3797 | + $access = ($this->isFrontend() ? 'sc.privateweb=0' : '1="'.$_SESSION['mgrRole'].'" OR sc.privatemgr=0').(!$docgrp ? '' : ' OR dg.document_group IN ('.$docgrp.')'); |
|
| 3798 | 3798 | |
| 3799 | 3799 | $tblsc = $this->getFullTableName('site_content'); |
| 3800 | 3800 | $tbldg = $this->getFullTableName('document_groups'); |
| 3801 | 3801 | |
| 3802 | 3802 | $result = $this->db->select("DISTINCT {$fields}", "{$tblsc} sc |
| 3803 | - LEFT JOIN {$tbldg} dg on dg.document = sc.id", "(sc.id IN (" . implode(',', $ids) . ") {$published} {$deleted} {$where}) AND ({$access}) GROUP BY sc.id", ($sort ? "{$sort} {$dir}" : ""), $limit); |
|
| 3803 | + LEFT JOIN {$tbldg} dg on dg.document = sc.id", "(sc.id IN (".implode(',', $ids).") {$published} {$deleted} {$where}) AND ({$access}) GROUP BY sc.id", ($sort ? "{$sort} {$dir}" : ""), $limit); |
|
| 3804 | 3804 | |
| 3805 | 3805 | $resourceArray = $this->db->makeArray($result); |
| 3806 | 3806 | |
@@ -3905,12 +3905,12 @@ discard block |
||
| 3905 | 3905 | $tbldg = $this->getFullTableName("document_groups"); |
| 3906 | 3906 | $activeSql = $active == 1 ? "AND sc.published=1 AND sc.deleted=0" : ""; |
| 3907 | 3907 | // modify field names to use sc. table reference |
| 3908 | - $fields = 'sc.' . implode(',sc.', array_filter(array_map('trim', explode(',', $fields)))); |
|
| 3908 | + $fields = 'sc.'.implode(',sc.', array_filter(array_map('trim', explode(',', $fields)))); |
|
| 3909 | 3909 | // get document groups for current user |
| 3910 | 3910 | if ($docgrp = $this->getUserDocGroups()) { |
| 3911 | 3911 | $docgrp = implode(",", $docgrp); |
| 3912 | 3912 | } |
| 3913 | - $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='" . $_SESSION['mgrRole'] . "' OR sc.privatemgr=0") . (!$docgrp ? "" : " OR dg.document_group IN ($docgrp)"); |
|
| 3913 | + $access = ($this->isFrontend() ? "sc.privateweb=0" : "1='".$_SESSION['mgrRole']."' OR sc.privatemgr=0").(!$docgrp ? "" : " OR dg.document_group IN ($docgrp)"); |
|
| 3914 | 3914 | $result = $this->db->select($fields, "{$tblsc} sc LEFT JOIN {$tbldg} dg on dg.document = sc.id", "(sc.id='{$pageid}' {$activeSql}) AND ({$access})", "", 1); |
| 3915 | 3915 | $pageInfo = $this->db->getRow($result); |
| 3916 | 3916 | |
@@ -3957,7 +3957,7 @@ discard block |
||
| 3957 | 3957 | { |
| 3958 | 3958 | if ($this->currentSnippet) { |
| 3959 | 3959 | $tbl = $this->getFullTableName("site_snippets"); |
| 3960 | - $rs = $this->db->select('id', $tbl, "name='" . $this->db->escape($this->currentSnippet) . "'", '', 1); |
|
| 3960 | + $rs = $this->db->select('id', $tbl, "name='".$this->db->escape($this->currentSnippet)."'", '', 1); |
|
| 3961 | 3961 | if ($snippetId = $this->db->getValue($rs)) { |
| 3962 | 3962 | return $snippetId; |
| 3963 | 3963 | } |
@@ -3984,23 +3984,23 @@ discard block |
||
| 3984 | 3984 | */ |
| 3985 | 3985 | public function clearCache($type = '', $report = false) |
| 3986 | 3986 | { |
| 3987 | - $cache_dir = MODX_BASE_PATH . $this->getCacheFolder(); |
|
| 3987 | + $cache_dir = MODX_BASE_PATH.$this->getCacheFolder(); |
|
| 3988 | 3988 | if (is_array($type)) { |
| 3989 | 3989 | foreach ($type as $_) { |
| 3990 | 3990 | $this->clearCache($_, $report); |
| 3991 | 3991 | } |
| 3992 | 3992 | } elseif ($type == 'full') { |
| 3993 | - include_once(MODX_MANAGER_PATH . 'processors/cache_sync.class.processor.php'); |
|
| 3993 | + include_once(MODX_MANAGER_PATH.'processors/cache_sync.class.processor.php'); |
|
| 3994 | 3994 | $sync = new synccache(); |
| 3995 | 3995 | $sync->setCachepath($cache_dir); |
| 3996 | 3996 | $sync->setReport($report); |
| 3997 | 3997 | $sync->emptyCache(); |
| 3998 | 3998 | } elseif (preg_match('@^[1-9][0-9]*$@', $type)) { |
| 3999 | 3999 | $key = ($this->config['cache_type'] == 2) ? $this->makePageCacheKey($type) : $type; |
| 4000 | - $file_name = "docid_" . $key . "_*.pageCache.php"; |
|
| 4001 | - $cache_path = $cache_dir . $file_name; |
|
| 4000 | + $file_name = "docid_".$key."_*.pageCache.php"; |
|
| 4001 | + $cache_path = $cache_dir.$file_name; |
|
| 4002 | 4002 | $files = glob($cache_path); |
| 4003 | - $files[] = $cache_dir . "docid_" . $key . ".pageCache.php"; |
|
| 4003 | + $files[] = $cache_dir."docid_".$key.".pageCache.php"; |
|
| 4004 | 4004 | foreach ($files as $file) { |
| 4005 | 4005 | if (!is_file($file)) { |
| 4006 | 4006 | continue; |
@@ -4008,7 +4008,7 @@ discard block |
||
| 4008 | 4008 | unlink($file); |
| 4009 | 4009 | } |
| 4010 | 4010 | } else { |
| 4011 | - $files = glob($cache_dir . '*'); |
|
| 4011 | + $files = glob($cache_dir.'*'); |
|
| 4012 | 4012 | foreach ($files as $file) { |
| 4013 | 4013 | $name = basename($file); |
| 4014 | 4014 | if (strpos($name, '.pageCache.php') === false) { |
@@ -4077,7 +4077,7 @@ discard block |
||
| 4077 | 4077 | $f_url_suffix = '/'; |
| 4078 | 4078 | } |
| 4079 | 4079 | |
| 4080 | - $alPath = !empty ($al['path']) ? $al['path'] . '/' : ''; |
|
| 4080 | + $alPath = !empty ($al['path']) ? $al['path'].'/' : ''; |
|
| 4081 | 4081 | |
| 4082 | 4082 | if ($al && $al['alias']) { |
| 4083 | 4083 | $alias = $al['alias']; |
@@ -4085,7 +4085,7 @@ discard block |
||
| 4085 | 4085 | |
| 4086 | 4086 | } |
| 4087 | 4087 | |
| 4088 | - $alias = $alPath . $f_url_prefix . $alias . $f_url_suffix; |
|
| 4088 | + $alias = $alPath.$f_url_prefix.$alias.$f_url_suffix; |
|
| 4089 | 4089 | $url = "{$alias}{$args}"; |
| 4090 | 4090 | } else { |
| 4091 | 4091 | $url = "index.php?id={$id}{$args}"; |
@@ -4104,7 +4104,7 @@ discard block |
||
| 4104 | 4104 | } |
| 4105 | 4105 | |
| 4106 | 4106 | //TODO: check to make sure that $site_url incudes the url :port (e.g. :8080) |
| 4107 | - $host = $scheme == 'full' ? $this->config['site_url'] : $scheme . '://' . $_SERVER['HTTP_HOST'] . $host; |
|
| 4107 | + $host = $scheme == 'full' ? $this->config['site_url'] : $scheme.'://'.$_SERVER['HTTP_HOST'].$host; |
|
| 4108 | 4108 | } |
| 4109 | 4109 | |
| 4110 | 4110 | //fix strictUrl by Bumkaka |
@@ -4113,9 +4113,9 @@ discard block |
||
| 4113 | 4113 | } |
| 4114 | 4114 | |
| 4115 | 4115 | if ($this->config['xhtml_urls']) { |
| 4116 | - $url = preg_replace("/&(?!amp;)/", "&", $host . $virtualDir . $url); |
|
| 4116 | + $url = preg_replace("/&(?!amp;)/", "&", $host.$virtualDir.$url); |
|
| 4117 | 4117 | } else { |
| 4118 | - $url = $host . $virtualDir . $url; |
|
| 4118 | + $url = $host.$virtualDir.$url; |
|
| 4119 | 4119 | } |
| 4120 | 4120 | |
| 4121 | 4121 | $evtOut = $this->invokeEvent('OnMakeDocUrl', array( |
@@ -4139,21 +4139,21 @@ discard block |
||
| 4139 | 4139 | if (isset($this->aliasListing[$id])) { |
| 4140 | 4140 | $out = $this->aliasListing[$id]; |
| 4141 | 4141 | } else { |
| 4142 | - $q = $this->db->query("SELECT id,alias,isfolder,parent FROM " . $this->getFullTableName("site_content") . " WHERE id=" . (int)$id); |
|
| 4142 | + $q = $this->db->query("SELECT id,alias,isfolder,parent FROM ".$this->getFullTableName("site_content")." WHERE id=".(int) $id); |
|
| 4143 | 4143 | if ($this->db->getRecordCount($q) == '1') { |
| 4144 | 4144 | $q = $this->db->getRow($q); |
| 4145 | 4145 | $this->aliasListing[$id] = array( |
| 4146 | - 'id' => (int)$q['id'], |
|
| 4146 | + 'id' => (int) $q['id'], |
|
| 4147 | 4147 | 'alias' => $q['alias'] == '' ? $q['id'] : $q['alias'], |
| 4148 | - 'parent' => (int)$q['parent'], |
|
| 4149 | - 'isfolder' => (int)$q['isfolder'], |
|
| 4148 | + 'parent' => (int) $q['parent'], |
|
| 4149 | + 'isfolder' => (int) $q['isfolder'], |
|
| 4150 | 4150 | ); |
| 4151 | 4151 | if ($this->aliasListing[$id]['parent'] > 0) { |
| 4152 | 4152 | //fix alias_path_usage |
| 4153 | 4153 | if ($this->config['use_alias_path'] == '1') { |
| 4154 | 4154 | //&& $tmp['path'] != '' - fix error slash with epty path |
| 4155 | 4155 | $tmp = $this->getAliasListing($this->aliasListing[$id]['parent']); |
| 4156 | - $this->aliasListing[$id]['path'] = $tmp['path'] . ($tmp['alias_visible'] ? (($tmp['parent'] > 0 && $tmp['path'] != '') ? '/' : '') . $tmp['alias'] : ''); |
|
| 4156 | + $this->aliasListing[$id]['path'] = $tmp['path'].($tmp['alias_visible'] ? (($tmp['parent'] > 0 && $tmp['path'] != '') ? '/' : '').$tmp['alias'] : ''); |
|
| 4157 | 4157 | } else { |
| 4158 | 4158 | $this->aliasListing[$id]['path'] = ''; |
| 4159 | 4159 | } |
@@ -4194,7 +4194,7 @@ discard block |
||
| 4194 | 4194 | $out = array(); |
| 4195 | 4195 | if (empty($this->version) || !is_array($this->version)) { |
| 4196 | 4196 | //include for compatibility modx version < 1.0.10 |
| 4197 | - include MODX_MANAGER_PATH . "includes/version.inc.php"; |
|
| 4197 | + include MODX_MANAGER_PATH."includes/version.inc.php"; |
|
| 4198 | 4198 | $this->version = array(); |
| 4199 | 4199 | $this->version['version'] = isset($modx_version) ? $modx_version : ''; |
| 4200 | 4200 | $this->version['branch'] = isset($modx_branch) ? $modx_branch : ''; |
@@ -4216,18 +4216,18 @@ discard block |
||
| 4216 | 4216 | { |
| 4217 | 4217 | if (isset ($this->snippetCache[$snippetName])) { |
| 4218 | 4218 | $snippet = $this->snippetCache[$snippetName]; |
| 4219 | - $properties = !empty($this->snippetCache[$snippetName . "Props"]) ? $this->snippetCache[$snippetName . "Props"] : ''; |
|
| 4219 | + $properties = !empty($this->snippetCache[$snippetName."Props"]) ? $this->snippetCache[$snippetName."Props"] : ''; |
|
| 4220 | 4220 | } else { // not in cache so let's check the db |
| 4221 | - $sql = "SELECT ss.`name`, ss.`snippet`, ss.`properties`, sm.properties as `sharedproperties` FROM " . $this->getFullTableName("site_snippets") . " as ss LEFT JOIN " . $this->getFullTableName('site_modules') . " as sm on sm.guid=ss.moduleguid WHERE ss.`name`='" . $this->db->escape($snippetName) . "' AND ss.disabled=0;"; |
|
| 4221 | + $sql = "SELECT ss.`name`, ss.`snippet`, ss.`properties`, sm.properties as `sharedproperties` FROM ".$this->getFullTableName("site_snippets")." as ss LEFT JOIN ".$this->getFullTableName('site_modules')." as sm on sm.guid=ss.moduleguid WHERE ss.`name`='".$this->db->escape($snippetName)."' AND ss.disabled=0;"; |
|
| 4222 | 4222 | $result = $this->db->query($sql); |
| 4223 | 4223 | if ($this->db->getRecordCount($result) == 1) { |
| 4224 | 4224 | $row = $this->db->getRow($result); |
| 4225 | 4225 | $snippet = $this->snippetCache[$snippetName] = $row['snippet']; |
| 4226 | 4226 | $mergedProperties = array_merge($this->parseProperties($row['properties']), $this->parseProperties($row['sharedproperties'])); |
| 4227 | - $properties = $this->snippetCache[$snippetName . "Props"] = json_encode($mergedProperties); |
|
| 4227 | + $properties = $this->snippetCache[$snippetName."Props"] = json_encode($mergedProperties); |
|
| 4228 | 4228 | } else { |
| 4229 | 4229 | $snippet = $this->snippetCache[$snippetName] = "return false;"; |
| 4230 | - $properties = $this->snippetCache[$snippetName . "Props"] = ''; |
|
| 4230 | + $properties = $this->snippetCache[$snippetName."Props"] = ''; |
|
| 4231 | 4231 | } |
| 4232 | 4232 | } |
| 4233 | 4233 | // load default params/properties |
@@ -4327,8 +4327,8 @@ discard block |
||
| 4327 | 4327 | } |
| 4328 | 4328 | if (strpos($tpl, $s) !== false) { |
| 4329 | 4329 | $tpl = str_replace($s, $value, $tpl); |
| 4330 | - } elseif($this->debug) { |
|
| 4331 | - $this->addLog('parseText parse error', $_SERVER['REQUEST_URI'] . $s, 2); |
|
| 4330 | + } elseif ($this->debug) { |
|
| 4331 | + $this->addLog('parseText parse error', $_SERVER['REQUEST_URI'].$s, 2); |
|
| 4332 | 4332 | } |
| 4333 | 4333 | } |
| 4334 | 4334 | |
@@ -4377,7 +4377,7 @@ discard block |
||
| 4377 | 4377 | case 'CODE': |
| 4378 | 4378 | break; |
| 4379 | 4379 | case 'FILE': |
| 4380 | - $template = file_get_contents(MODX_BASE_PATH . $template); |
|
| 4380 | + $template = file_get_contents(MODX_BASE_PATH.$template); |
|
| 4381 | 4381 | break; |
| 4382 | 4382 | case 'CHUNK': |
| 4383 | 4383 | $template = $this->getChunk($template); |
@@ -4410,7 +4410,7 @@ discard block |
||
| 4410 | 4410 | if ($mode !== 'formatOnly' && empty($timestamp)) { |
| 4411 | 4411 | return '-'; |
| 4412 | 4412 | } |
| 4413 | - $timestamp = (int)$timestamp; |
|
| 4413 | + $timestamp = (int) $timestamp; |
|
| 4414 | 4414 | |
| 4415 | 4415 | switch ($this->config['datetime_format']) { |
| 4416 | 4416 | case 'YYYY/mm/dd': |
@@ -4430,7 +4430,7 @@ discard block |
||
| 4430 | 4430 | } |
| 4431 | 4431 | |
| 4432 | 4432 | if (empty($mode)) { |
| 4433 | - $strTime = strftime($dateFormat . " %H:%M:%S", $timestamp); |
|
| 4433 | + $strTime = strftime($dateFormat." %H:%M:%S", $timestamp); |
|
| 4434 | 4434 | } elseif ($mode == 'dateOnly') { |
| 4435 | 4435 | $strTime = strftime($dateFormat, $timestamp); |
| 4436 | 4436 | } elseif ($mode == 'formatOnly') { |
@@ -4484,7 +4484,7 @@ discard block |
||
| 4484 | 4484 | $S = 0; |
| 4485 | 4485 | } |
| 4486 | 4486 | $timeStamp = mktime($H, $M, $S, $m, $d, $Y); |
| 4487 | - $timeStamp = (int)$timeStamp; |
|
| 4487 | + $timeStamp = (int) $timeStamp; |
|
| 4488 | 4488 | return $timeStamp; |
| 4489 | 4489 | } |
| 4490 | 4490 | |
@@ -4526,7 +4526,7 @@ discard block |
||
| 4526 | 4526 | if ($v === 'value') { |
| 4527 | 4527 | unset($_[$i]); |
| 4528 | 4528 | } else { |
| 4529 | - $_[$i] = 'tv.' . $v; |
|
| 4529 | + $_[$i] = 'tv.'.$v; |
|
| 4530 | 4530 | } |
| 4531 | 4531 | } |
| 4532 | 4532 | $fields = join(',', $_); |
@@ -4535,12 +4535,12 @@ discard block |
||
| 4535 | 4535 | } |
| 4536 | 4536 | |
| 4537 | 4537 | if ($tvsort != '') { |
| 4538 | - $tvsort = 'tv.' . join(',tv.', array_filter(array_map('trim', explode(',', $tvsort)))); |
|
| 4538 | + $tvsort = 'tv.'.join(',tv.', array_filter(array_map('trim', explode(',', $tvsort)))); |
|
| 4539 | 4539 | } |
| 4540 | 4540 | if ($tvidnames == "*") { |
| 4541 | 4541 | $query = "tv.id<>0"; |
| 4542 | 4542 | } else { |
| 4543 | - $query = (is_numeric($tvidnames[0]) ? "tv.id" : "tv.name") . " IN ('" . join("','", $tvidnames) . "')"; |
|
| 4543 | + $query = (is_numeric($tvidnames[0]) ? "tv.id" : "tv.name")." IN ('".join("','", $tvidnames)."')"; |
|
| 4544 | 4544 | } |
| 4545 | 4545 | |
| 4546 | 4546 | $this->getUserDocGroups(); |
@@ -4684,7 +4684,7 @@ discard block |
||
| 4684 | 4684 | return $this->tmpCache[__FUNCTION__][$cacheKey]; |
| 4685 | 4685 | } |
| 4686 | 4686 | |
| 4687 | - if (($idnames != '*' && !is_array($idnames)) || empty($idnames) ) { |
|
| 4687 | + if (($idnames != '*' && !is_array($idnames)) || empty($idnames)) { |
|
| 4688 | 4688 | return false; |
| 4689 | 4689 | } else { |
| 4690 | 4690 | |
@@ -4702,23 +4702,23 @@ discard block |
||
| 4702 | 4702 | } |
| 4703 | 4703 | |
| 4704 | 4704 | // get user defined template variables |
| 4705 | - $fields = ($fields == '') ? 'tv.*' : 'tv.' . implode(',tv.', array_filter(array_map('trim', explode(',', $fields)))); |
|
| 4706 | - $sort = ($sort == '') ? '' : 'tv.' . implode(',tv.', array_filter(array_map('trim', explode(',', $sort)))); |
|
| 4705 | + $fields = ($fields == '') ? 'tv.*' : 'tv.'.implode(',tv.', array_filter(array_map('trim', explode(',', $fields)))); |
|
| 4706 | + $sort = ($sort == '') ? '' : 'tv.'.implode(',tv.', array_filter(array_map('trim', explode(',', $sort)))); |
|
| 4707 | 4707 | |
| 4708 | 4708 | if ($idnames == '*') { |
| 4709 | 4709 | $query = 'tv.id<>0'; |
| 4710 | 4710 | } else { |
| 4711 | - $query = (is_numeric($idnames[0]) ? 'tv.id' : 'tv.name') . " IN ('" . implode("','", $idnames) . "')"; |
|
| 4711 | + $query = (is_numeric($idnames[0]) ? 'tv.id' : 'tv.name')." IN ('".implode("','", $idnames)."')"; |
|
| 4712 | 4712 | } |
| 4713 | 4713 | |
| 4714 | - $rs = $this->db->select("{$fields}, IF(tvc.value != '', tvc.value, tv.default_text) as value", $this->getFullTableName('site_tmplvars') . " tv |
|
| 4715 | - INNER JOIN " . $this->getFullTableName('site_tmplvar_templates') . " tvtpl ON tvtpl.tmplvarid = tv.id |
|
| 4716 | - LEFT JOIN " . $this->getFullTableName('site_tmplvar_contentvalues') . " tvc ON tvc.tmplvarid=tv.id AND tvc.contentid = '{$docid}'", "{$query} AND tvtpl.templateid = '{$docRow['template']}'", ($sort ? "{$sort} {$dir}" : "")); |
|
| 4714 | + $rs = $this->db->select("{$fields}, IF(tvc.value != '', tvc.value, tv.default_text) as value", $this->getFullTableName('site_tmplvars')." tv |
|
| 4715 | + INNER JOIN " . $this->getFullTableName('site_tmplvar_templates')." tvtpl ON tvtpl.tmplvarid = tv.id |
|
| 4716 | + LEFT JOIN " . $this->getFullTableName('site_tmplvar_contentvalues')." tvc ON tvc.tmplvarid=tv.id AND tvc.contentid = '{$docid}'", "{$query} AND tvtpl.templateid = '{$docRow['template']}'", ($sort ? "{$sort} {$dir}" : "")); |
|
| 4717 | 4717 | |
| 4718 | 4718 | $result = $this->db->makeArray($rs); |
| 4719 | 4719 | |
| 4720 | 4720 | // get default/built-in template variables |
| 4721 | - if(is_array($docRow)){ |
|
| 4721 | + if (is_array($docRow)) { |
|
| 4722 | 4722 | ksort($docRow); |
| 4723 | 4723 | |
| 4724 | 4724 | foreach ($docRow as $key => $value) { |
@@ -4756,22 +4756,22 @@ discard block |
||
| 4756 | 4756 | */ |
| 4757 | 4757 | public function getTemplateVarOutput($idnames = array(), $docid = '', $published = 1, $sep = '') |
| 4758 | 4758 | { |
| 4759 | - if (is_array($idnames) && empty($idnames) ) { |
|
| 4759 | + if (is_array($idnames) && empty($idnames)) { |
|
| 4760 | 4760 | return false; |
| 4761 | 4761 | } else { |
| 4762 | 4762 | $output = array(); |
| 4763 | 4763 | $vars = ($idnames == '*' || is_array($idnames)) ? $idnames : array($idnames); |
| 4764 | 4764 | |
| 4765 | - $docid = (int)$docid > 0 ? (int)$docid : $this->documentIdentifier; |
|
| 4765 | + $docid = (int) $docid > 0 ? (int) $docid : $this->documentIdentifier; |
|
| 4766 | 4766 | // remove sort for speed |
| 4767 | 4767 | $result = $this->getTemplateVars($vars, '*', $docid, $published, '', ''); |
| 4768 | 4768 | |
| 4769 | 4769 | if ($result == false) { |
| 4770 | 4770 | return false; |
| 4771 | 4771 | } else { |
| 4772 | - $baspath = MODX_MANAGER_PATH . 'includes'; |
|
| 4773 | - include_once $baspath . '/tmplvars.format.inc.php'; |
|
| 4774 | - include_once $baspath . '/tmplvars.commands.inc.php'; |
|
| 4772 | + $baspath = MODX_MANAGER_PATH.'includes'; |
|
| 4773 | + include_once $baspath.'/tmplvars.format.inc.php'; |
|
| 4774 | + include_once $baspath.'/tmplvars.commands.inc.php'; |
|
| 4775 | 4775 | |
| 4776 | 4776 | for ($i = 0; $i < count($result); $i++) { |
| 4777 | 4777 | $row = $result[$i]; |
@@ -4796,7 +4796,7 @@ discard block |
||
| 4796 | 4796 | */ |
| 4797 | 4797 | public function getFullTableName($tbl) |
| 4798 | 4798 | { |
| 4799 | - return $this->db->config['dbase'] . ".`" . $this->db->config['table_prefix'] . $tbl . "`"; |
|
| 4799 | + return $this->db->config['dbase'].".`".$this->db->config['table_prefix'].$tbl."`"; |
|
| 4800 | 4800 | } |
| 4801 | 4801 | |
| 4802 | 4802 | /** |
@@ -4875,7 +4875,7 @@ discard block |
||
| 4875 | 4875 | public function getCachePath() |
| 4876 | 4876 | { |
| 4877 | 4877 | global $base_url; |
| 4878 | - $pth = $base_url . $this->getCacheFolder(); |
|
| 4878 | + $pth = $base_url.$this->getCacheFolder(); |
|
| 4879 | 4879 | return $pth; |
| 4880 | 4880 | } |
| 4881 | 4881 | |
@@ -4927,8 +4927,8 @@ discard block |
||
| 4927 | 4927 | $out = false; |
| 4928 | 4928 | |
| 4929 | 4929 | if (!empty($context)) { |
| 4930 | - if (is_scalar($context) && isset($_SESSION[$context . 'Validated'])) { |
|
| 4931 | - $out = $_SESSION[$context . 'InternalKey']; |
|
| 4930 | + if (is_scalar($context) && isset($_SESSION[$context.'Validated'])) { |
|
| 4931 | + $out = $_SESSION[$context.'InternalKey']; |
|
| 4932 | 4932 | } |
| 4933 | 4933 | } else { |
| 4934 | 4934 | switch (true) { |
@@ -4956,8 +4956,8 @@ discard block |
||
| 4956 | 4956 | $out = false; |
| 4957 | 4957 | |
| 4958 | 4958 | if (!empty($context)) { |
| 4959 | - if (is_scalar($context) && isset($_SESSION[$context . 'Validated'])) { |
|
| 4960 | - $out = $_SESSION[$context . 'Shortname']; |
|
| 4959 | + if (is_scalar($context) && isset($_SESSION[$context.'Validated'])) { |
|
| 4960 | + $out = $_SESSION[$context.'Shortname']; |
|
| 4961 | 4961 | } |
| 4962 | 4962 | } else { |
| 4963 | 4963 | switch (true) { |
@@ -5028,8 +5028,8 @@ discard block |
||
| 5028 | 5028 | */ |
| 5029 | 5029 | public function getWebUserInfo($uid) |
| 5030 | 5030 | { |
| 5031 | - $rs = $this->db->select('wu.username, wu.password, wua.*', $this->getFullTableName("web_users") . " wu |
|
| 5032 | - INNER JOIN " . $this->getFullTableName("web_user_attributes") . " wua ON wua.internalkey=wu.id", "wu.id='{$uid}'"); |
|
| 5031 | + $rs = $this->db->select('wu.username, wu.password, wua.*', $this->getFullTableName("web_users")." wu |
|
| 5032 | + INNER JOIN " . $this->getFullTableName("web_user_attributes")." wua ON wua.internalkey=wu.id", "wu.id='{$uid}'"); |
|
| 5033 | 5033 | if ($row = $this->db->getRow($rs)) { |
| 5034 | 5034 | if (!isset($row['usertype']) or !$row["usertype"]) { |
| 5035 | 5035 | $row["usertype"] = "web"; |
@@ -5065,7 +5065,7 @@ discard block |
||
| 5065 | 5065 | } else if (is_array($dg)) { |
| 5066 | 5066 | // resolve ids to names |
| 5067 | 5067 | $dgn = array(); |
| 5068 | - $ds = $this->db->select('name', $this->getFullTableName("documentgroup_names"), "id IN (" . implode(",", $dg) . ")"); |
|
| 5068 | + $ds = $this->db->select('name', $this->getFullTableName("documentgroup_names"), "id IN (".implode(",", $dg).")"); |
|
| 5069 | 5069 | while ($row = $this->db->getRow($ds)) { |
| 5070 | 5070 | $dgn[] = $row['name']; |
| 5071 | 5071 | } |
@@ -5093,7 +5093,7 @@ discard block |
||
| 5093 | 5093 | $rt = false; |
| 5094 | 5094 | if ($_SESSION["webValidated"] == 1) { |
| 5095 | 5095 | $tbl = $this->getFullTableName("web_users"); |
| 5096 | - $ds = $this->db->select('id, username, password', $tbl, "id='" . $this->getLoginUserID() . "'"); |
|
| 5096 | + $ds = $this->db->select('id, username, password', $tbl, "id='".$this->getLoginUserID()."'"); |
|
| 5097 | 5097 | if ($row = $this->db->getRow($ds)) { |
| 5098 | 5098 | if ($row["password"] == md5($oldPwd)) { |
| 5099 | 5099 | if (strlen($newPwd) < 6) { |
@@ -5103,7 +5103,7 @@ discard block |
||
| 5103 | 5103 | } else { |
| 5104 | 5104 | $this->db->update(array( |
| 5105 | 5105 | 'password' => $this->db->escape($newPwd), |
| 5106 | - ), $tbl, "id='" . $this->getLoginUserID() . "'"); |
|
| 5106 | + ), $tbl, "id='".$this->getLoginUserID()."'"); |
|
| 5107 | 5107 | // invoke OnWebChangePassword event |
| 5108 | 5108 | $this->invokeEvent("OnWebChangePassword", array( |
| 5109 | 5109 | "userid" => $row["id"], |
@@ -5134,8 +5134,8 @@ discard block |
||
| 5134 | 5134 | // check cache |
| 5135 | 5135 | $grpNames = isset ($_SESSION['webUserGroupNames']) ? $_SESSION['webUserGroupNames'] : false; |
| 5136 | 5136 | if (!is_array($grpNames)) { |
| 5137 | - $rs = $this->db->select('wgn.name', $this->getFullTableName("webgroup_names") . " wgn |
|
| 5138 | - INNER JOIN " . $this->getFullTableName("web_groups") . " wg ON wg.webgroup=wgn.id AND wg.webuser='" . $this->getLoginUserID() . "'"); |
|
| 5137 | + $rs = $this->db->select('wgn.name', $this->getFullTableName("webgroup_names")." wgn |
|
| 5138 | + INNER JOIN " . $this->getFullTableName("web_groups")." wg ON wg.webgroup=wgn.id AND wg.webuser='".$this->getLoginUserID()."'"); |
|
| 5139 | 5139 | $grpNames = $this->db->getColumn("name", $rs); |
| 5140 | 5140 | // save to cache |
| 5141 | 5141 | $_SESSION['webUserGroupNames'] = $grpNames; |
@@ -5168,7 +5168,7 @@ discard block |
||
| 5168 | 5168 | if (strpos(strtolower($src), "<style") !== false || strpos(strtolower($src), "<link") !== false) { |
| 5169 | 5169 | $this->sjscripts[$nextpos] = $src; |
| 5170 | 5170 | } else { |
| 5171 | - $this->sjscripts[$nextpos] = "\t" . '<link rel="stylesheet" type="text/css" href="' . $src . '" ' . ($media ? 'media="' . $media . '" ' : '') . '/>'; |
|
| 5171 | + $this->sjscripts[$nextpos] = "\t".'<link rel="stylesheet" type="text/css" href="'.$src.'" '.($media ? 'media="'.$media.'" ' : '').'/>'; |
|
| 5172 | 5172 | } |
| 5173 | 5173 | } |
| 5174 | 5174 | |
@@ -5247,7 +5247,7 @@ discard block |
||
| 5247 | 5247 | } |
| 5248 | 5248 | |
| 5249 | 5249 | if ($useThisVer && $plaintext != true && (strpos(strtolower($src), "<script") === false)) { |
| 5250 | - $src = "\t" . '<script type="text/javascript" src="' . $src . '"></script>'; |
|
| 5250 | + $src = "\t".'<script type="text/javascript" src="'.$src.'"></script>'; |
|
| 5251 | 5251 | } |
| 5252 | 5252 | if ($startup) { |
| 5253 | 5253 | $pos = isset($overwritepos) ? $overwritepos : max(array_merge(array(0), array_keys($this->sjscripts))) + 1; |
@@ -5393,7 +5393,7 @@ discard block |
||
| 5393 | 5393 | $eventtime = $this->getMicroTime() - $eventtime; |
| 5394 | 5394 | $this->pluginsCode .= sprintf('<fieldset><legend><b>%s / %s</b> (%2.2f ms)</legend>', $evtName, $pluginName, $eventtime * 1000); |
| 5395 | 5395 | foreach ($parameter as $k => $v) { |
| 5396 | - $this->pluginsCode .= "{$k} => " . print_r($v, true) . '<br>'; |
|
| 5396 | + $this->pluginsCode .= "{$k} => ".print_r($v, true).'<br>'; |
|
| 5397 | 5397 | } |
| 5398 | 5398 | $this->pluginsCode .= '</fieldset><br />'; |
| 5399 | 5399 | $this->pluginsTime["{$evtName} / {$pluginName}"] += $eventtime; |
@@ -5421,13 +5421,13 @@ discard block |
||
| 5421 | 5421 | $plugin = array(); |
| 5422 | 5422 | if (isset ($this->pluginCache[$pluginName])) { |
| 5423 | 5423 | $pluginCode = $this->pluginCache[$pluginName]; |
| 5424 | - $pluginProperties = isset($this->pluginCache[$pluginName . "Props"]) ? $this->pluginCache[$pluginName . "Props"] : ''; |
|
| 5424 | + $pluginProperties = isset($this->pluginCache[$pluginName."Props"]) ? $this->pluginCache[$pluginName."Props"] : ''; |
|
| 5425 | 5425 | } else { |
| 5426 | 5426 | $pluginName = $this->db->escape($pluginName); |
| 5427 | 5427 | $result = $this->db->select('name, plugincode, properties', $this->getFullTableName("site_plugins"), "name='{$pluginName}' AND disabled=0"); |
| 5428 | 5428 | if ($row = $this->db->getRow($result)) { |
| 5429 | 5429 | $pluginCode = $this->pluginCache[$row['name']] = $row['plugincode']; |
| 5430 | - $pluginProperties = $this->pluginCache[$row['name'] . "Props"] = $row['properties']; |
|
| 5430 | + $pluginProperties = $this->pluginCache[$row['name']."Props"] = $row['properties']; |
|
| 5431 | 5431 | } else { |
| 5432 | 5432 | $pluginCode = $this->pluginCache[$pluginName] = "return false;"; |
| 5433 | 5433 | $pluginProperties = ''; |
@@ -5534,7 +5534,7 @@ discard block |
||
| 5534 | 5534 | public function parseDocBlockFromFile($element_dir, $filename, $escapeValues = false) |
| 5535 | 5535 | { |
| 5536 | 5536 | $params = array(); |
| 5537 | - $fullpath = $element_dir . '/' . $filename; |
|
| 5537 | + $fullpath = $element_dir.'/'.$filename; |
|
| 5538 | 5538 | if (is_readable($fullpath)) { |
| 5539 | 5539 | $tpl = @fopen($fullpath, "r"); |
| 5540 | 5540 | if ($tpl) { |
@@ -5701,8 +5701,8 @@ discard block |
||
| 5701 | 5701 | $ph = array('site_url' => MODX_SITE_URL); |
| 5702 | 5702 | $regexUrl = "/((http|https|ftp|ftps)\:\/\/[^\/]+(\/[^\s]+[^,.?!:;\s])?)/"; |
| 5703 | 5703 | $regexEmail = '#([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-wyz][a-z](fo|g|l|m|mes|o|op|pa|ro|seum|t|u|v|z)?)#i'; |
| 5704 | - $emailSubject = isset($parsed['name']) ? '?subject=' . $parsed['name'] : ''; |
|
| 5705 | - $emailSubject .= isset($parsed['version']) ? ' v' . $parsed['version'] : ''; |
|
| 5704 | + $emailSubject = isset($parsed['name']) ? '?subject='.$parsed['name'] : ''; |
|
| 5705 | + $emailSubject .= isset($parsed['version']) ? ' v'.$parsed['version'] : ''; |
|
| 5706 | 5706 | foreach ($parsed as $key => $val) { |
| 5707 | 5707 | if (is_array($val)) { |
| 5708 | 5708 | foreach ($val as $key2 => $val2) { |
@@ -5711,7 +5711,7 @@ discard block |
||
| 5711 | 5711 | $val2 = preg_replace($regexUrl, "<a href=\"{$url[0]}\" target=\"_blank\">{$url[0]}</a> ", $val2); |
| 5712 | 5712 | } |
| 5713 | 5713 | if (preg_match($regexEmail, $val2, $url)) { |
| 5714 | - $val2 = preg_replace($regexEmail, '<a href="mailto:\\1' . $emailSubject . '">\\1</a>', $val2); |
|
| 5714 | + $val2 = preg_replace($regexEmail, '<a href="mailto:\\1'.$emailSubject.'">\\1</a>', $val2); |
|
| 5715 | 5715 | } |
| 5716 | 5716 | $parsed[$key][$key2] = $val2; |
| 5717 | 5717 | } |
@@ -5721,7 +5721,7 @@ discard block |
||
| 5721 | 5721 | $val = preg_replace($regexUrl, "<a href=\"{$url[0]}\" target=\"_blank\">{$url[0]}</a> ", $val); |
| 5722 | 5722 | } |
| 5723 | 5723 | if (preg_match($regexEmail, $val, $url)) { |
| 5724 | - $val = preg_replace($regexEmail, '<a href="mailto:\\1' . $emailSubject . '">\\1</a>', $val); |
|
| 5724 | + $val = preg_replace($regexEmail, '<a href="mailto:\\1'.$emailSubject.'">\\1</a>', $val); |
|
| 5725 | 5725 | } |
| 5726 | 5726 | $parsed[$key] = $val; |
| 5727 | 5727 | } |
@@ -5735,32 +5735,32 @@ discard block |
||
| 5735 | 5735 | ); |
| 5736 | 5736 | |
| 5737 | 5737 | $nl = "\n"; |
| 5738 | - $list = isset($parsed['logo']) ? '<img src="' . $this->config['base_url'] . ltrim($parsed['logo'], "/") . '" style="float:right;max-width:100px;height:auto;" />' . $nl : ''; |
|
| 5739 | - $list .= '<p>' . $nl; |
|
| 5740 | - $list .= isset($parsed['name']) ? '<strong>' . $parsed['name'] . '</strong><br/>' . $nl : ''; |
|
| 5741 | - $list .= isset($parsed['description']) ? $parsed['description'] . $nl : ''; |
|
| 5742 | - $list .= '</p><br/>' . $nl; |
|
| 5743 | - $list .= isset($parsed['version']) ? '<p><strong>' . $_lang['version'] . ':</strong> ' . $parsed['version'] . '</p>' . $nl : ''; |
|
| 5744 | - $list .= isset($parsed['license']) ? '<p><strong>' . $_lang['license'] . ':</strong> ' . $parsed['license'] . '</p>' . $nl : ''; |
|
| 5745 | - $list .= isset($parsed['lastupdate']) ? '<p><strong>' . $_lang['last_update'] . ':</strong> ' . $parsed['lastupdate'] . '</p>' . $nl : ''; |
|
| 5746 | - $list .= '<br/>' . $nl; |
|
| 5738 | + $list = isset($parsed['logo']) ? '<img src="'.$this->config['base_url'].ltrim($parsed['logo'], "/").'" style="float:right;max-width:100px;height:auto;" />'.$nl : ''; |
|
| 5739 | + $list .= '<p>'.$nl; |
|
| 5740 | + $list .= isset($parsed['name']) ? '<strong>'.$parsed['name'].'</strong><br/>'.$nl : ''; |
|
| 5741 | + $list .= isset($parsed['description']) ? $parsed['description'].$nl : ''; |
|
| 5742 | + $list .= '</p><br/>'.$nl; |
|
| 5743 | + $list .= isset($parsed['version']) ? '<p><strong>'.$_lang['version'].':</strong> '.$parsed['version'].'</p>'.$nl : ''; |
|
| 5744 | + $list .= isset($parsed['license']) ? '<p><strong>'.$_lang['license'].':</strong> '.$parsed['license'].'</p>'.$nl : ''; |
|
| 5745 | + $list .= isset($parsed['lastupdate']) ? '<p><strong>'.$_lang['last_update'].':</strong> '.$parsed['lastupdate'].'</p>'.$nl : ''; |
|
| 5746 | + $list .= '<br/>'.$nl; |
|
| 5747 | 5747 | $first = true; |
| 5748 | 5748 | foreach ($arrayParams as $param => $label) { |
| 5749 | 5749 | if (isset($parsed[$param])) { |
| 5750 | 5750 | if ($first) { |
| 5751 | - $list .= '<p><strong>' . $_lang['references'] . '</strong></p>' . $nl; |
|
| 5752 | - $list .= '<ul class="docBlockList">' . $nl; |
|
| 5751 | + $list .= '<p><strong>'.$_lang['references'].'</strong></p>'.$nl; |
|
| 5752 | + $list .= '<ul class="docBlockList">'.$nl; |
|
| 5753 | 5753 | $first = false; |
| 5754 | 5754 | } |
| 5755 | - $list .= ' <li><strong>' . $label . '</strong>' . $nl; |
|
| 5756 | - $list .= ' <ul>' . $nl; |
|
| 5755 | + $list .= ' <li><strong>'.$label.'</strong>'.$nl; |
|
| 5756 | + $list .= ' <ul>'.$nl; |
|
| 5757 | 5757 | foreach ($parsed[$param] as $val) { |
| 5758 | - $list .= ' <li>' . $val . '</li>' . $nl; |
|
| 5758 | + $list .= ' <li>'.$val.'</li>'.$nl; |
|
| 5759 | 5759 | } |
| 5760 | - $list .= ' </ul></li>' . $nl; |
|
| 5760 | + $list .= ' </ul></li>'.$nl; |
|
| 5761 | 5761 | } |
| 5762 | 5762 | } |
| 5763 | - $list .= !$first ? '</ul>' . $nl : ''; |
|
| 5763 | + $list .= !$first ? '</ul>'.$nl : ''; |
|
| 5764 | 5764 | |
| 5765 | 5765 | return $list; |
| 5766 | 5766 | } |
@@ -5836,7 +5836,7 @@ discard block |
||
| 5836 | 5836 | */ |
| 5837 | 5837 | public function addSnippet($name, $phpCode) |
| 5838 | 5838 | { |
| 5839 | - $this->snippetCache['#' . $name] = $phpCode; |
|
| 5839 | + $this->snippetCache['#'.$name] = $phpCode; |
|
| 5840 | 5840 | } |
| 5841 | 5841 | |
| 5842 | 5842 | /** |
@@ -5845,7 +5845,7 @@ discard block |
||
| 5845 | 5845 | */ |
| 5846 | 5846 | public function addChunk($name, $text) |
| 5847 | 5847 | { |
| 5848 | - $this->chunkCache['#' . $name] = $text; |
|
| 5848 | + $this->chunkCache['#'.$name] = $text; |
|
| 5849 | 5849 | } |
| 5850 | 5850 | |
| 5851 | 5851 | /** |
@@ -5881,7 +5881,7 @@ discard block |
||
| 5881 | 5881 | } |
| 5882 | 5882 | |
| 5883 | 5883 | if (!$isSafe) { |
| 5884 | - $msg = $phpcode . "\n" . $this->currentSnippet . "\n" . print_r($_SERVER, true); |
|
| 5884 | + $msg = $phpcode."\n".$this->currentSnippet."\n".print_r($_SERVER, true); |
|
| 5885 | 5885 | $title = sprintf('Unknown eval was executed (%s)', $this->htmlspecialchars(substr(trim($phpcode), 0, 50))); |
| 5886 | 5886 | $this->messageQuit($title, '', true, '', '', 'Parser', $msg); |
| 5887 | 5887 | return; |
@@ -5895,7 +5895,7 @@ discard block |
||
| 5895 | 5895 | return 'array()'; |
| 5896 | 5896 | } |
| 5897 | 5897 | |
| 5898 | - $output = $echo . $return; |
|
| 5898 | + $output = $echo.$return; |
|
| 5899 | 5899 | modx_sanitize_gpc($output); |
| 5900 | 5900 | return $this->htmlspecialchars($output); // Maybe, all html tags are dangerous |
| 5901 | 5901 | } |
@@ -5913,8 +5913,8 @@ discard block |
||
| 5913 | 5913 | |
| 5914 | 5914 | $safe = explode(',', $safe_functions); |
| 5915 | 5915 | |
| 5916 | - $phpcode = rtrim($phpcode, ';') . ';'; |
|
| 5917 | - $tokens = token_get_all('<?php ' . $phpcode); |
|
| 5916 | + $phpcode = rtrim($phpcode, ';').';'; |
|
| 5917 | + $tokens = token_get_all('<?php '.$phpcode); |
|
| 5918 | 5918 | foreach ($tokens as $i => $token) { |
| 5919 | 5919 | if (!is_array($token)) { |
| 5920 | 5920 | continue; |
@@ -5950,7 +5950,7 @@ discard block |
||
| 5950 | 5950 | public function atBindFileContent($str = '') |
| 5951 | 5951 | { |
| 5952 | 5952 | |
| 5953 | - $search_path = array('assets/tvs/', 'assets/chunks/', 'assets/templates/', $this->config['rb_base_url'] . 'files/', ''); |
|
| 5953 | + $search_path = array('assets/tvs/', 'assets/chunks/', 'assets/templates/', $this->config['rb_base_url'].'files/', ''); |
|
| 5954 | 5954 | |
| 5955 | 5955 | if (stripos($str, '@FILE') !== 0) { |
| 5956 | 5956 | return $str; |
@@ -5973,7 +5973,7 @@ discard block |
||
| 5973 | 5973 | $errorMsg = sprintf("Could not retrieve string '%s'.", $str); |
| 5974 | 5974 | |
| 5975 | 5975 | foreach ($search_path as $path) { |
| 5976 | - $file_path = MODX_BASE_PATH . $path . $str; |
|
| 5976 | + $file_path = MODX_BASE_PATH.$path.$str; |
|
| 5977 | 5977 | if (strpos($file_path, MODX_MANAGER_PATH) === 0) { |
| 5978 | 5978 | return $errorMsg; |
| 5979 | 5979 | } elseif (is_file($file_path)) { |
@@ -5987,7 +5987,7 @@ discard block |
||
| 5987 | 5987 | return $errorMsg; |
| 5988 | 5988 | } |
| 5989 | 5989 | |
| 5990 | - $content = (string)file_get_contents($file_path); |
|
| 5990 | + $content = (string) file_get_contents($file_path); |
|
| 5991 | 5991 | if ($content === false) { |
| 5992 | 5992 | return $errorMsg; |
| 5993 | 5993 | } |
@@ -6100,22 +6100,22 @@ discard block |
||
| 6100 | 6100 | |
| 6101 | 6101 | $version = isset ($GLOBALS['modx_version']) ? $GLOBALS['modx_version'] : ''; |
| 6102 | 6102 | $release_date = isset ($GLOBALS['release_date']) ? $GLOBALS['release_date'] : ''; |
| 6103 | - $request_uri = "http://" . $_SERVER['HTTP_HOST'] . ($_SERVER["SERVER_PORT"] == 80 ? "" : (":" . $_SERVER["SERVER_PORT"])) . $_SERVER['REQUEST_URI']; |
|
| 6103 | + $request_uri = "http://".$_SERVER['HTTP_HOST'].($_SERVER["SERVER_PORT"] == 80 ? "" : (":".$_SERVER["SERVER_PORT"])).$_SERVER['REQUEST_URI']; |
|
| 6104 | 6104 | $request_uri = $this->htmlspecialchars($request_uri, ENT_QUOTES, $this->config['modx_charset']); |
| 6105 | 6105 | $ua = $this->htmlspecialchars($_SERVER['HTTP_USER_AGENT'], ENT_QUOTES, $this->config['modx_charset']); |
| 6106 | 6106 | $referer = $this->htmlspecialchars($_SERVER['HTTP_REFERER'], ENT_QUOTES, $this->config['modx_charset']); |
| 6107 | 6107 | if ($is_error) { |
| 6108 | 6108 | $str = '<h2 style="color:red">« Evo Parse Error »</h2>'; |
| 6109 | 6109 | if ($msg != 'PHP Parse Error') { |
| 6110 | - $str .= '<h3 style="color:red">' . $msg . '</h3>'; |
|
| 6110 | + $str .= '<h3 style="color:red">'.$msg.'</h3>'; |
|
| 6111 | 6111 | } |
| 6112 | 6112 | } else { |
| 6113 | 6113 | $str = '<h2 style="color:#003399">« Evo Debug/ stop message »</h2>'; |
| 6114 | - $str .= '<h3 style="color:#003399">' . $msg . '</h3>'; |
|
| 6114 | + $str .= '<h3 style="color:#003399">'.$msg.'</h3>'; |
|
| 6115 | 6115 | } |
| 6116 | 6116 | |
| 6117 | 6117 | if (!empty ($query)) { |
| 6118 | - $str .= '<div style="font-weight:bold;border:1px solid #ccc;padding:8px;color:#333;background-color:#ffffcd;margin-bottom:15px;">SQL > <span id="sqlHolder">' . $query . '</span></div>'; |
|
| 6118 | + $str .= '<div style="font-weight:bold;border:1px solid #ccc;padding:8px;color:#333;background-color:#ffffcd;margin-bottom:15px;">SQL > <span id="sqlHolder">'.$query.'</span></div>'; |
|
| 6119 | 6119 | } |
| 6120 | 6120 | |
| 6121 | 6121 | $errortype = array( |
@@ -6138,13 +6138,13 @@ discard block |
||
| 6138 | 6138 | |
| 6139 | 6139 | if (!empty($nr) || !empty($file)) { |
| 6140 | 6140 | if ($text != '') { |
| 6141 | - $str .= '<div style="font-weight:bold;border:1px solid #ccc;padding:8px;color:#333;background-color:#ffffcd;margin-bottom:15px;">Error : ' . $text . '</div>'; |
|
| 6141 | + $str .= '<div style="font-weight:bold;border:1px solid #ccc;padding:8px;color:#333;background-color:#ffffcd;margin-bottom:15px;">Error : '.$text.'</div>'; |
|
| 6142 | 6142 | } |
| 6143 | 6143 | if ($output != '') { |
| 6144 | - $str .= '<div style="font-weight:bold;border:1px solid #ccc;padding:8px;color:#333;background-color:#ffffcd;margin-bottom:15px;">' . $output . '</div>'; |
|
| 6144 | + $str .= '<div style="font-weight:bold;border:1px solid #ccc;padding:8px;color:#333;background-color:#ffffcd;margin-bottom:15px;">'.$output.'</div>'; |
|
| 6145 | 6145 | } |
| 6146 | 6146 | if ($nr !== '') { |
| 6147 | - $table[] = array('ErrorType[num]', $errortype [$nr] . "[" . $nr . "]"); |
|
| 6147 | + $table[] = array('ErrorType[num]', $errortype [$nr]."[".$nr."]"); |
|
| 6148 | 6148 | } |
| 6149 | 6149 | if ($file) { |
| 6150 | 6150 | $table[] = array('File', $file); |
@@ -6164,7 +6164,7 @@ discard block |
||
| 6164 | 6164 | } |
| 6165 | 6165 | |
| 6166 | 6166 | if (!empty($this->event->activePlugin)) { |
| 6167 | - $table[] = array('Current Plugin', $this->event->activePlugin . '(' . $this->event->name . ')'); |
|
| 6167 | + $table[] = array('Current Plugin', $this->event->activePlugin.'('.$this->event->name.')'); |
|
| 6168 | 6168 | } |
| 6169 | 6169 | |
| 6170 | 6170 | $str .= $MakeTable->create($table, array('Error information', '')); |
@@ -6174,17 +6174,17 @@ discard block |
||
| 6174 | 6174 | $table[] = array('REQUEST_URI', $request_uri); |
| 6175 | 6175 | |
| 6176 | 6176 | if ($this->manager->action) { |
| 6177 | - include_once(MODX_MANAGER_PATH . 'includes/actionlist.inc.php'); |
|
| 6177 | + include_once(MODX_MANAGER_PATH.'includes/actionlist.inc.php'); |
|
| 6178 | 6178 | global $action_list; |
| 6179 | 6179 | $actionName = (isset($action_list[$this->manager->action])) ? " - {$action_list[$this->manager->action]}" : ''; |
| 6180 | 6180 | |
| 6181 | - $table[] = array('Manager action', $this->manager->action . $actionName); |
|
| 6181 | + $table[] = array('Manager action', $this->manager->action.$actionName); |
|
| 6182 | 6182 | } |
| 6183 | 6183 | |
| 6184 | 6184 | if (preg_match('@^[0-9]+@', $this->documentIdentifier)) { |
| 6185 | 6185 | $resource = $this->getDocumentObject('id', $this->documentIdentifier); |
| 6186 | 6186 | $url = $this->makeUrl($this->documentIdentifier, '', '', 'full'); |
| 6187 | - $table[] = array('Resource', '[' . $this->documentIdentifier . '] <a href="' . $url . '" target="_blank">' . $resource['pagetitle'] . '</a>'); |
|
| 6187 | + $table[] = array('Resource', '['.$this->documentIdentifier.'] <a href="'.$url.'" target="_blank">'.$resource['pagetitle'].'</a>'); |
|
| 6188 | 6188 | } |
| 6189 | 6189 | $table[] = array('Referer', $referer); |
| 6190 | 6190 | $table[] = array('User Agent', $ua); |
@@ -6205,7 +6205,7 @@ discard block |
||
| 6205 | 6205 | |
| 6206 | 6206 | $mem = memory_get_peak_usage(true); |
| 6207 | 6207 | $total_mem = $mem - $this->mstart; |
| 6208 | - $total_mem = ($total_mem / 1024 / 1024) . ' mb'; |
|
| 6208 | + $total_mem = ($total_mem / 1024 / 1024).' mb'; |
|
| 6209 | 6209 | |
| 6210 | 6210 | $queryTime = $this->queryTime; |
| 6211 | 6211 | $phpTime = $totalTime - $queryTime; |
@@ -6226,18 +6226,18 @@ discard block |
||
| 6226 | 6226 | $str .= $this->get_backtrace(debug_backtrace()); |
| 6227 | 6227 | // Log error |
| 6228 | 6228 | if (!empty($this->currentSnippet)) { |
| 6229 | - $source = 'Snippet - ' . $this->currentSnippet; |
|
| 6229 | + $source = 'Snippet - '.$this->currentSnippet; |
|
| 6230 | 6230 | } elseif (!empty($this->event->activePlugin)) { |
| 6231 | - $source = 'Plugin - ' . $this->event->activePlugin; |
|
| 6231 | + $source = 'Plugin - '.$this->event->activePlugin; |
|
| 6232 | 6232 | } elseif ($source !== '') { |
| 6233 | - $source = 'Parser - ' . $source; |
|
| 6233 | + $source = 'Parser - '.$source; |
|
| 6234 | 6234 | } elseif ($query !== '') { |
| 6235 | 6235 | $source = 'SQL Query'; |
| 6236 | 6236 | } else { |
| 6237 | 6237 | $source = 'Parser'; |
| 6238 | 6238 | } |
| 6239 | 6239 | if ($msg) { |
| 6240 | - $source .= ' / ' . $msg; |
|
| 6240 | + $source .= ' / '.$msg; |
|
| 6241 | 6241 | } |
| 6242 | 6242 | if (isset($actionName) && !empty($actionName)) { |
| 6243 | 6243 | $source .= $actionName; |
@@ -6269,12 +6269,12 @@ discard block |
||
| 6269 | 6269 | |
| 6270 | 6270 | // Display error |
| 6271 | 6271 | if (isset($_SESSION['mgrValidated'])) { |
| 6272 | - echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head><title>EVO Content Manager ' . $version . ' » ' . $release_date . '</title> |
|
| 6272 | + echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html><head><title>EVO Content Manager '.$version.' » '.$release_date.'</title> |
|
| 6273 | 6273 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 6274 | - <link rel="stylesheet" type="text/css" href="' . $this->config['site_manager_url'] . 'media/style/' . $this->config['manager_theme'] . '/style.css" /> |
|
| 6274 | + <link rel="stylesheet" type="text/css" href="' . $this->config['site_manager_url'].'media/style/'.$this->config['manager_theme'].'/style.css" /> |
|
| 6275 | 6275 | <style type="text/css">body { padding:10px; } td {font:inherit;}</style> |
| 6276 | 6276 | </head><body> |
| 6277 | - ' . $str . '</body></html>'; |
|
| 6277 | + ' . $str.'</body></html>'; |
|
| 6278 | 6278 | |
| 6279 | 6279 | } else { |
| 6280 | 6280 | echo 'Error'; |
@@ -6312,7 +6312,7 @@ discard block |
||
| 6312 | 6312 | switch ($val['type']) { |
| 6313 | 6313 | case '->': |
| 6314 | 6314 | case '::': |
| 6315 | - $functionName = $val['function'] = $val['class'] . $val['type'] . $val['function']; |
|
| 6315 | + $functionName = $val['function'] = $val['class'].$val['type'].$val['function']; |
|
| 6316 | 6316 | break; |
| 6317 | 6317 | default: |
| 6318 | 6318 | $functionName = $val['function']; |
@@ -6322,7 +6322,7 @@ discard block |
||
| 6322 | 6322 | $args = array_pad(array(), $_, '$var'); |
| 6323 | 6323 | $args = implode(", ", $args); |
| 6324 | 6324 | $modx = &$this; |
| 6325 | - $args = preg_replace_callback('/\$var/', function () use ($modx, &$tmp, $val) { |
|
| 6325 | + $args = preg_replace_callback('/\$var/', function() use ($modx, &$tmp, $val) { |
|
| 6326 | 6326 | $arg = $val['args'][$tmp - 1]; |
| 6327 | 6327 | switch (true) { |
| 6328 | 6328 | case is_null($arg): { |
@@ -6334,7 +6334,7 @@ discard block |
||
| 6334 | 6334 | break; |
| 6335 | 6335 | } |
| 6336 | 6336 | case is_scalar($arg): { |
| 6337 | - $out = strlen($arg) > 20 ? 'string $var' . $tmp : ("'" . $this->htmlspecialchars(str_replace("'", "\\'", $arg)) . "'"); |
|
| 6337 | + $out = strlen($arg) > 20 ? 'string $var'.$tmp : ("'".$this->htmlspecialchars(str_replace("'", "\\'", $arg))."'"); |
|
| 6338 | 6338 | break; |
| 6339 | 6339 | } |
| 6340 | 6340 | case is_bool($arg): { |
@@ -6342,23 +6342,23 @@ discard block |
||
| 6342 | 6342 | break; |
| 6343 | 6343 | } |
| 6344 | 6344 | case is_array($arg): { |
| 6345 | - $out = 'array $var' . $tmp; |
|
| 6345 | + $out = 'array $var'.$tmp; |
|
| 6346 | 6346 | break; |
| 6347 | 6347 | } |
| 6348 | 6348 | case is_object($arg): { |
| 6349 | - $out = get_class($arg) . ' $var' . $tmp; |
|
| 6349 | + $out = get_class($arg).' $var'.$tmp; |
|
| 6350 | 6350 | break; |
| 6351 | 6351 | } |
| 6352 | 6352 | default: { |
| 6353 | - $out = '$var' . $tmp; |
|
| 6353 | + $out = '$var'.$tmp; |
|
| 6354 | 6354 | } |
| 6355 | 6355 | } |
| 6356 | 6356 | $tmp++; |
| 6357 | 6357 | return $out; |
| 6358 | 6358 | }, $args); |
| 6359 | 6359 | $line = array( |
| 6360 | - "<strong>" . $functionName . "</strong>(" . $args . ")", |
|
| 6361 | - $path . " on line " . $val['line'] |
|
| 6360 | + "<strong>".$functionName."</strong>(".$args.")", |
|
| 6361 | + $path." on line ".$val['line'] |
|
| 6362 | 6362 | ); |
| 6363 | 6363 | $table[] = array(implode("<br />", $line)); |
| 6364 | 6364 | } |
@@ -6399,7 +6399,7 @@ discard block |
||
| 6399 | 6399 | $alias = strip_tags($alias); // strip HTML |
| 6400 | 6400 | $alias = preg_replace('/[^\.A-Za-z0-9 _-]/', '', $alias); // strip non-alphanumeric characters |
| 6401 | 6401 | $alias = preg_replace('/\s+/', '-', $alias); // convert white-space to dash |
| 6402 | - $alias = preg_replace('/-+/', '-', $alias); // convert multiple dashes to one |
|
| 6402 | + $alias = preg_replace('/-+/', '-', $alias); // convert multiple dashes to one |
|
| 6403 | 6403 | $alias = trim($alias, '-'); // trim excess |
| 6404 | 6404 | return $alias; |
| 6405 | 6405 | } |
@@ -6415,7 +6415,7 @@ discard block |
||
| 6415 | 6415 | $precisions = count($sizes) - 1; |
| 6416 | 6416 | foreach ($sizes as $unit => $bytes) { |
| 6417 | 6417 | if ($size >= $bytes) { |
| 6418 | - return number_format($size / $bytes, $precisions) . ' ' . $unit; |
|
| 6418 | + return number_format($size / $bytes, $precisions).' '.$unit; |
|
| 6419 | 6419 | } |
| 6420 | 6420 | $precisions--; |
| 6421 | 6421 | } |
@@ -6519,10 +6519,10 @@ discard block |
||
| 6519 | 6519 | |
| 6520 | 6520 | if (strpos($str, MODX_MANAGER_PATH) === 0) { |
| 6521 | 6521 | return false; |
| 6522 | - } elseif (is_file(MODX_BASE_PATH . $str)) { |
|
| 6523 | - $file_path = MODX_BASE_PATH . $str; |
|
| 6524 | - } elseif (is_file(MODX_BASE_PATH . "{$tpl_dir}{$str}")) { |
|
| 6525 | - $file_path = MODX_BASE_PATH . $tpl_dir . $str; |
|
| 6522 | + } elseif (is_file(MODX_BASE_PATH.$str)) { |
|
| 6523 | + $file_path = MODX_BASE_PATH.$str; |
|
| 6524 | + } elseif (is_file(MODX_BASE_PATH."{$tpl_dir}{$str}")) { |
|
| 6525 | + $file_path = MODX_BASE_PATH.$tpl_dir.$str; |
|
| 6526 | 6526 | } else { |
| 6527 | 6527 | return false; |
| 6528 | 6528 | } |
@@ -6648,7 +6648,7 @@ discard block |
||
| 6648 | 6648 | $title = 'no title'; |
| 6649 | 6649 | } |
| 6650 | 6650 | if (is_array($msg)) { |
| 6651 | - $msg = '<pre>' . print_r($msg, true) . '</pre>'; |
|
| 6651 | + $msg = '<pre>'.print_r($msg, true).'</pre>'; |
|
| 6652 | 6652 | } elseif ($msg === '') { |
| 6653 | 6653 | $msg = $_SERVER['REQUEST_URI']; |
| 6654 | 6654 | } |
@@ -6693,7 +6693,7 @@ discard block |
||
| 6693 | 6693 | if (is_array($SystemAlertMsgQueque)) { |
| 6694 | 6694 | $title = ''; |
| 6695 | 6695 | if ($this->name && $this->activePlugin) { |
| 6696 | - $title = "<div><b>" . $this->activePlugin . "</b> - <span style='color:maroon;'>" . $this->name . "</span></div>"; |
|
| 6696 | + $title = "<div><b>".$this->activePlugin."</b> - <span style='color:maroon;'>".$this->name."</span></div>"; |
|
| 6697 | 6697 | } |
| 6698 | 6698 | $SystemAlertMsgQueque[] = "$title<div style='margin-left:10px;margin-top:3px;'>$msg</div>"; |
| 6699 | 6699 | } |
@@ -554,6 +554,7 @@ discard block |
||
| 554 | 554 | * @name: getColumn |
| 555 | 555 | * @desc: returns an array of the values found on colun $name |
| 556 | 556 | * @param: $dsq - dataset or query string |
| 557 | + * @param string $name |
|
| 557 | 558 | */ |
| 558 | 559 | public function getColumn($name, $dsq) |
| 559 | 560 | { |
@@ -720,6 +721,9 @@ discard block |
||
| 720 | 721 | return $result; |
| 721 | 722 | } |
| 722 | 723 | |
| 724 | + /** |
|
| 725 | + * @param string $table_name |
|
| 726 | + */ |
|
| 723 | 727 | public function optimize($table_name) |
| 724 | 728 | { |
| 725 | 729 | $rs = $this->query("OPTIMIZE TABLE {$table_name}"); |
@@ -742,6 +746,9 @@ discard block |
||
| 742 | 746 | return mysql_data_seek($result, $row_number); |
| 743 | 747 | } |
| 744 | 748 | |
| 749 | + /** |
|
| 750 | + * @return string |
|
| 751 | + */ |
|
| 745 | 752 | public function _getFieldsStringFromArray($fields = array()) |
| 746 | 753 | { |
| 747 | 754 | |
@@ -761,6 +768,9 @@ discard block |
||
| 761 | 768 | return join(',', $_); |
| 762 | 769 | } |
| 763 | 770 | |
| 771 | + /** |
|
| 772 | + * @return string |
|
| 773 | + */ |
|
| 764 | 774 | public function _getFromStringFromArray($tables = array()) |
| 765 | 775 | { |
| 766 | 776 | $_ = array(); |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | $pre = null, |
| 31 | 31 | $charset = '', |
| 32 | 32 | $connection_method = 'SET CHARACTER SET' |
| 33 | - ) { |
|
| 33 | + ){ |
|
| 34 | 34 | $this->config['host'] = $host ? $host : $GLOBALS['database_server']; |
| 35 | 35 | $this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase']; |
| 36 | 36 | $this->config['user'] = $uid ? $uid : $GLOBALS['database_user']; |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | $referer = $modx->htmlspecialchars($_SERVER['HTTP_REFERER']); |
| 121 | 121 | |
| 122 | 122 | $modx->sendmail(array( |
| 123 | - 'subject' => 'Missing to create the database connection! from ' . $modx->config['site_name'], |
|
| 123 | + 'subject' => 'Missing to create the database connection! from '.$modx->config['site_name'], |
|
| 124 | 124 | 'body' => "{$logtitle}\n{$request_uri}\n{$ua}\n{$referer}", |
| 125 | 125 | 'type' => 'text' |
| 126 | 126 | ) |
@@ -137,15 +137,15 @@ discard block |
||
| 137 | 137 | } else { |
| 138 | 138 | $dbase = trim($dbase, '`'); // remove the `` chars |
| 139 | 139 | if (!@ mysql_select_db($dbase, $this->conn)) { |
| 140 | - $modx->messageQuit("Failed to select the database '" . $dbase . "'!"); |
|
| 140 | + $modx->messageQuit("Failed to select the database '".$dbase."'!"); |
|
| 141 | 141 | exit; |
| 142 | 142 | } |
| 143 | 143 | @mysql_query("{$connection_method} {$charset}", $this->conn); |
| 144 | 144 | $tend = $modx->getMicroTime(); |
| 145 | 145 | $totaltime = $tend - $tstart; |
| 146 | 146 | if ($modx->dumpSQL) { |
| 147 | - $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>" . sprintf("Database connection was created in %2.4f s", |
|
| 148 | - $totaltime) . "</fieldset><br />"; |
|
| 147 | + $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>".sprintf("Database connection was created in %2.4f s", |
|
| 148 | + $totaltime)."</fieldset><br />"; |
|
| 149 | 149 | } |
| 150 | 150 | if (function_exists('mysql_set_charset')) { |
| 151 | 151 | mysql_set_charset($this->config['charset']); |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | case 1091: |
| 226 | 226 | break; |
| 227 | 227 | default: |
| 228 | - $modx->messageQuit('Execution of a query to the database failed - ' . $this->getLastError(), $sql); |
|
| 228 | + $modx->messageQuit('Execution of a query to the database failed - '.$this->getLastError(), $sql); |
|
| 229 | 229 | } |
| 230 | 230 | } else { |
| 231 | 231 | $tend = $modx->getMicroTime(); |
@@ -239,24 +239,24 @@ discard block |
||
| 239 | 239 | $debug_path[] = $line['function']; |
| 240 | 240 | } |
| 241 | 241 | $debug_path = implode(' > ', array_reverse($debug_path)); |
| 242 | - $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query " . ($modx->executedQueries + 1) . " - " . sprintf("%2.2f ms", |
|
| 243 | - $totaltime * 1000) . "</legend>"; |
|
| 244 | - $modx->queryCode .= $sql . '<br><br>'; |
|
| 242 | + $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query ".($modx->executedQueries + 1)." - ".sprintf("%2.2f ms", |
|
| 243 | + $totaltime * 1000)."</legend>"; |
|
| 244 | + $modx->queryCode .= $sql.'<br><br>'; |
|
| 245 | 245 | if ($modx->event->name) { |
| 246 | - $modx->queryCode .= 'Current Event => ' . $modx->event->name . '<br>'; |
|
| 246 | + $modx->queryCode .= 'Current Event => '.$modx->event->name.'<br>'; |
|
| 247 | 247 | } |
| 248 | 248 | if ($modx->event->activePlugin) { |
| 249 | - $modx->queryCode .= 'Current Plugin => ' . $modx->event->activePlugin . '<br>'; |
|
| 249 | + $modx->queryCode .= 'Current Plugin => '.$modx->event->activePlugin.'<br>'; |
|
| 250 | 250 | } |
| 251 | 251 | if ($modx->currentSnippet) { |
| 252 | - $modx->queryCode .= 'Current Snippet => ' . $modx->currentSnippet . '<br>'; |
|
| 252 | + $modx->queryCode .= 'Current Snippet => '.$modx->currentSnippet.'<br>'; |
|
| 253 | 253 | } |
| 254 | 254 | if (stripos($sql, 'select') === 0) { |
| 255 | - $modx->queryCode .= 'Record Count => ' . $this->getRecordCount($result) . '<br>'; |
|
| 255 | + $modx->queryCode .= 'Record Count => '.$this->getRecordCount($result).'<br>'; |
|
| 256 | 256 | } else { |
| 257 | - $modx->queryCode .= 'Affected Rows => ' . $this->getAffectedRows() . '<br>'; |
|
| 257 | + $modx->queryCode .= 'Affected Rows => '.$this->getAffectedRows().'<br>'; |
|
| 258 | 258 | } |
| 259 | - $modx->queryCode .= 'Functions Path => ' . $debug_path . '<br>'; |
|
| 259 | + $modx->queryCode .= 'Functions Path => '.$debug_path.'<br>'; |
|
| 260 | 260 | $modx->queryCode .= "</fieldset><br />"; |
| 261 | 261 | } |
| 262 | 262 | $modx->executedQueries = $modx->executedQueries + 1; |
@@ -350,9 +350,9 @@ discard block |
||
| 350 | 350 | if (is_null($value) || strtolower($value) === 'null') { |
| 351 | 351 | $flds = 'NULL'; |
| 352 | 352 | } else { |
| 353 | - $flds = "'" . $value . "'"; |
|
| 353 | + $flds = "'".$value."'"; |
|
| 354 | 354 | } |
| 355 | - $fields[$key] = "`{$key}` = " . $flds; |
|
| 355 | + $fields[$key] = "`{$key}` = ".$flds; |
|
| 356 | 356 | } |
| 357 | 357 | $fields = implode(",", $fields); |
| 358 | 358 | } |
@@ -380,13 +380,13 @@ discard block |
||
| 380 | 380 | $this->query("INSERT INTO {$intotable} {$fields}"); |
| 381 | 381 | } else { |
| 382 | 382 | if (empty($fromtable)) { |
| 383 | - $fields = "(`" . implode("`, `", array_keys($fields)) . "`) VALUES('" . implode("', '", |
|
| 384 | - array_values($fields)) . "')"; |
|
| 383 | + $fields = "(`".implode("`, `", array_keys($fields))."`) VALUES('".implode("', '", |
|
| 384 | + array_values($fields))."')"; |
|
| 385 | 385 | $rt = $this->query("INSERT INTO {$intotable} {$fields}"); |
| 386 | 386 | } else { |
| 387 | 387 | if (version_compare($this->getVersion(), "4.0.14") >= 0) { |
| 388 | 388 | $fromtable = $this->replaceFullTableName($fromtable); |
| 389 | - $fields = "(" . implode(",", array_keys($fields)) . ")"; |
|
| 389 | + $fields = "(".implode(",", array_keys($fields)).")"; |
|
| 390 | 390 | $where = trim($where); |
| 391 | 391 | $limit = trim($limit); |
| 392 | 392 | if ($where !== '' && stripos($where, 'WHERE') !== 0) { |
@@ -399,8 +399,8 @@ discard block |
||
| 399 | 399 | } else { |
| 400 | 400 | $ds = $this->select($fromfields, $fromtable, $where, '', $limit); |
| 401 | 401 | while ($row = $this->getRow($ds)) { |
| 402 | - $fields = "(" . implode(",", array_keys($fields)) . ") VALUES('" . implode("', '", |
|
| 403 | - $row) . "')"; |
|
| 402 | + $fields = "(".implode(",", array_keys($fields)).") VALUES('".implode("', '", |
|
| 403 | + $row)."')"; |
|
| 404 | 404 | $rt = $this->query("INSERT INTO {$intotable} {$fields}"); |
| 405 | 405 | } |
| 406 | 406 | } |
@@ -485,7 +485,7 @@ discard block |
||
| 485 | 485 | public function getInsertId($conn = null) |
| 486 | 486 | { |
| 487 | 487 | if (!is_resource($conn)) { |
| 488 | - $conn =& $this->conn; |
|
| 488 | + $conn = & $this->conn; |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | return mysql_insert_id($conn); |
@@ -498,7 +498,7 @@ discard block |
||
| 498 | 498 | public function getAffectedRows($conn = null) |
| 499 | 499 | { |
| 500 | 500 | if (!is_resource($conn)) { |
| 501 | - $conn =& $this->conn; |
|
| 501 | + $conn = & $this->conn; |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | 504 | return mysql_affected_rows($conn); |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | public function getLastError($conn = null) |
| 512 | 512 | { |
| 513 | 513 | if (!is_resource($conn)) { |
| 514 | - $conn =& $this->conn; |
|
| 514 | + $conn = & $this->conn; |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | return mysql_error($conn); |
@@ -280,13 +280,13 @@ discard block |
||
| 280 | 280 | $orderby = trim($orderby); |
| 281 | 281 | $limit = trim($limit); |
| 282 | 282 | if ($where !== '' && stripos($where, 'WHERE') !== 0) { |
| 283 | - $where = "WHERE {$where}"; |
|
| 283 | + $where = "where {$where}"; |
|
| 284 | 284 | } |
| 285 | 285 | if ($orderby !== '' && stripos($orderby, 'ORDER BY') !== 0) { |
| 286 | 286 | $orderby = "ORDER BY {$orderby}"; |
| 287 | 287 | } |
| 288 | 288 | if ($limit !== '' && stripos($limit, 'LIMIT') !== 0) { |
| 289 | - $limit = "LIMIT {$limit}"; |
|
| 289 | + $limit = "limit {$limit}"; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | return $this->query("DELETE FROM {$from} {$where} {$orderby} {$limit}"); |
@@ -322,16 +322,16 @@ discard block |
||
| 322 | 322 | $orderby = trim($orderby); |
| 323 | 323 | $limit = trim($limit); |
| 324 | 324 | if ($where !== '' && stripos($where, 'WHERE') !== 0) { |
| 325 | - $where = "WHERE {$where}"; |
|
| 325 | + $where = "where {$where}"; |
|
| 326 | 326 | } |
| 327 | 327 | if ($orderby !== '' && stripos($orderby, 'ORDER') !== 0) { |
| 328 | 328 | $orderby = "ORDER BY {$orderby}"; |
| 329 | 329 | } |
| 330 | 330 | if ($limit !== '' && stripos($limit, 'LIMIT') !== 0) { |
| 331 | - $limit = "LIMIT {$limit}"; |
|
| 331 | + $limit = "limit {$limit}"; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}"); |
|
| 334 | + return $this->query("select {$fields} FROM {$from} {$where} {$orderby} {$limit}"); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -358,10 +358,10 @@ discard block |
||
| 358 | 358 | } |
| 359 | 359 | $where = trim($where); |
| 360 | 360 | if ($where !== '' && stripos($where, 'WHERE') !== 0) { |
| 361 | - $where = "WHERE {$where}"; |
|
| 361 | + $where = "where {$where}"; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | - return $this->query("UPDATE {$table} SET {$fields} {$where}"); |
|
| 364 | + return $this->query("update {$table} SET {$fields} {$where}"); |
|
| 365 | 365 | } |
| 366 | 366 | } |
| 367 | 367 | |
@@ -390,10 +390,10 @@ discard block |
||
| 390 | 390 | $where = trim($where); |
| 391 | 391 | $limit = trim($limit); |
| 392 | 392 | if ($where !== '' && stripos($where, 'WHERE') !== 0) { |
| 393 | - $where = "WHERE {$where}"; |
|
| 393 | + $where = "where {$where}"; |
|
| 394 | 394 | } |
| 395 | 395 | if ($limit !== '' && stripos($limit, 'LIMIT') !== 0) { |
| 396 | - $limit = "LIMIT {$limit}"; |
|
| 396 | + $limit = "limit {$limit}"; |
|
| 397 | 397 | } |
| 398 | 398 | $rt = $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}"); |
| 399 | 399 | } else { |
@@ -732,7 +732,7 @@ discard block |
||
| 732 | 732 | |
| 733 | 733 | public function truncate($table_name) |
| 734 | 734 | { |
| 735 | - $rs = $this->query("TRUNCATE {$table_name}"); |
|
| 735 | + $rs = $this->query("truncate {$table_name}"); |
|
| 736 | 736 | |
| 737 | 737 | return $rs; |
| 738 | 738 | } |
@@ -408,6 +408,9 @@ discard block |
||
| 408 | 408 | return $out; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | + /** |
|
| 412 | + * @param string $name |
|
| 413 | + */ |
|
| 411 | 414 | public function getColumn($name, $dsq) |
| 412 | 415 | { |
| 413 | 416 | if (!is_object($dsq)) { |
@@ -506,6 +509,9 @@ discard block |
||
| 506 | 509 | return $rsArray; |
| 507 | 510 | } |
| 508 | 511 | |
| 512 | + /** |
|
| 513 | + * @return string |
|
| 514 | + */ |
|
| 509 | 515 | public function getVersion() |
| 510 | 516 | { |
| 511 | 517 | return $this->conn->server_info; |
@@ -527,6 +533,9 @@ discard block |
||
| 527 | 533 | return $result; |
| 528 | 534 | } |
| 529 | 535 | |
| 536 | + /** |
|
| 537 | + * @param string $table_name |
|
| 538 | + */ |
|
| 530 | 539 | public function optimize($table_name) |
| 531 | 540 | { |
| 532 | 541 | $rs = $this->query("OPTIMIZE TABLE {$table_name}"); |
@@ -549,6 +558,9 @@ discard block |
||
| 549 | 558 | return $result->data_seek($row_number); |
| 550 | 559 | } |
| 551 | 560 | |
| 561 | + /** |
|
| 562 | + * @return string |
|
| 563 | + */ |
|
| 552 | 564 | public function _getFieldsStringFromArray($fields = array()) |
| 553 | 565 | { |
| 554 | 566 | |
@@ -568,6 +580,9 @@ discard block |
||
| 568 | 580 | return join(',', $_); |
| 569 | 581 | } |
| 570 | 582 | |
| 583 | + /** |
|
| 584 | + * @return string |
|
| 585 | + */ |
|
| 571 | 586 | public function _getFromStringFromArray($tables = array()) |
| 572 | 587 | { |
| 573 | 588 | $_ = array(); |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | $pre = null, |
| 20 | 20 | $charset = '', |
| 21 | 21 | $connection_method = 'SET CHARACTER SET' |
| 22 | - ) { |
|
| 22 | + ){ |
|
| 23 | 23 | $this->config['host'] = $host ? $host : $GLOBALS['database_server']; |
| 24 | 24 | $this->config['dbase'] = $dbase ? $dbase : $GLOBALS['dbase']; |
| 25 | 25 | $this->config['user'] = $uid ? $uid : $GLOBALS['database_user']; |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | $ua = $modx->htmlspecialchars($_SERVER['HTTP_USER_AGENT']); |
| 53 | 53 | $referer = $modx->htmlspecialchars($_SERVER['HTTP_REFERER']); |
| 54 | 54 | $modx->sendmail(array( |
| 55 | - 'subject' => 'Missing to create the database connection! from ' . $modx->config['site_name'], |
|
| 55 | + 'subject' => 'Missing to create the database connection! from '.$modx->config['site_name'], |
|
| 56 | 56 | 'body' => "{$logtitle}\n{$request_uri}\n{$ua}\n{$referer}", |
| 57 | 57 | 'type' => 'text' |
| 58 | 58 | )); |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | $tend = $modx->getMicroTime(); |
| 71 | 71 | $totaltime = $tend - $tstart; |
| 72 | 72 | if ($modx->dumpSQL) { |
| 73 | - $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>" . sprintf("Database connection was created in %2.4f s", |
|
| 74 | - $totaltime) . "</fieldset><br />"; |
|
| 73 | + $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>".sprintf("Database connection was created in %2.4f s", |
|
| 74 | + $totaltime)."</fieldset><br />"; |
|
| 75 | 75 | } |
| 76 | 76 | $this->conn->set_charset($this->config['charset']); |
| 77 | 77 | $this->isConnected = true; |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | case 1091: |
| 139 | 139 | break; |
| 140 | 140 | default: |
| 141 | - $modx->messageQuit('Execution of a query to the database failed - ' . $this->getLastError(), $sql); |
|
| 141 | + $modx->messageQuit('Execution of a query to the database failed - '.$this->getLastError(), $sql); |
|
| 142 | 142 | } |
| 143 | 143 | } else { |
| 144 | 144 | $tend = $modx->getMicroTime(); |
@@ -152,24 +152,24 @@ discard block |
||
| 152 | 152 | $debug_path[] = $line['function']; |
| 153 | 153 | } |
| 154 | 154 | $debug_path = implode(' > ', array_reverse($debug_path)); |
| 155 | - $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query " . ($modx->executedQueries + 1) . " - " . sprintf("%2.2f ms", |
|
| 156 | - $totaltime * 1000) . "</legend>"; |
|
| 157 | - $modx->queryCode .= $sql . '<br><br>'; |
|
| 155 | + $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query ".($modx->executedQueries + 1)." - ".sprintf("%2.2f ms", |
|
| 156 | + $totaltime * 1000)."</legend>"; |
|
| 157 | + $modx->queryCode .= $sql.'<br><br>'; |
|
| 158 | 158 | if ($modx->event->name) { |
| 159 | - $modx->queryCode .= 'Current Event => ' . $modx->event->name . '<br>'; |
|
| 159 | + $modx->queryCode .= 'Current Event => '.$modx->event->name.'<br>'; |
|
| 160 | 160 | } |
| 161 | 161 | if ($modx->event->activePlugin) { |
| 162 | - $modx->queryCode .= 'Current Plugin => ' . $modx->event->activePlugin . '<br>'; |
|
| 162 | + $modx->queryCode .= 'Current Plugin => '.$modx->event->activePlugin.'<br>'; |
|
| 163 | 163 | } |
| 164 | 164 | if ($modx->currentSnippet) { |
| 165 | - $modx->queryCode .= 'Current Snippet => ' . $modx->currentSnippet . '<br>'; |
|
| 165 | + $modx->queryCode .= 'Current Snippet => '.$modx->currentSnippet.'<br>'; |
|
| 166 | 166 | } |
| 167 | 167 | if (stripos($sql, 'select') === 0) { |
| 168 | - $modx->queryCode .= 'Record Count => ' . $this->getRecordCount($result) . '<br>'; |
|
| 168 | + $modx->queryCode .= 'Record Count => '.$this->getRecordCount($result).'<br>'; |
|
| 169 | 169 | } else { |
| 170 | - $modx->queryCode .= 'Affected Rows => ' . $this->getAffectedRows() . '<br>'; |
|
| 170 | + $modx->queryCode .= 'Affected Rows => '.$this->getAffectedRows().'<br>'; |
|
| 171 | 171 | } |
| 172 | - $modx->queryCode .= 'Functions Path => ' . $debug_path . '<br>'; |
|
| 172 | + $modx->queryCode .= 'Functions Path => '.$debug_path.'<br>'; |
|
| 173 | 173 | $modx->queryCode .= "</fieldset><br />"; |
| 174 | 174 | } |
| 175 | 175 | $modx->executedQueries = $modx->executedQueries + 1; |
@@ -252,9 +252,9 @@ discard block |
||
| 252 | 252 | if (is_null($value) || strtolower($value) === 'null') { |
| 253 | 253 | $flds = 'NULL'; |
| 254 | 254 | } else { |
| 255 | - $flds = "'" . $value . "'"; |
|
| 255 | + $flds = "'".$value."'"; |
|
| 256 | 256 | } |
| 257 | - $fields[$key] = "`{$key}` = " . $flds; |
|
| 257 | + $fields[$key] = "`{$key}` = ".$flds; |
|
| 258 | 258 | } |
| 259 | 259 | $fields = implode(",", $fields); |
| 260 | 260 | } |
@@ -278,12 +278,12 @@ discard block |
||
| 278 | 278 | $this->query("INSERT INTO {$intotable} {$fields}"); |
| 279 | 279 | } else { |
| 280 | 280 | if (empty($fromtable)) { |
| 281 | - $fields = "(`" . implode("`, `", array_keys($fields)) . "`) VALUES('" . implode("', '", |
|
| 282 | - array_values($fields)) . "')"; |
|
| 281 | + $fields = "(`".implode("`, `", array_keys($fields))."`) VALUES('".implode("', '", |
|
| 282 | + array_values($fields))."')"; |
|
| 283 | 283 | $rt = $this->query("INSERT INTO {$intotable} {$fields}"); |
| 284 | 284 | } else { |
| 285 | 285 | $fromtable = $this->replaceFullTableName($fromtable); |
| 286 | - $fields = "(" . implode(",", array_keys($fields)) . ")"; |
|
| 286 | + $fields = "(".implode(",", array_keys($fields)).")"; |
|
| 287 | 287 | $where = trim($where); |
| 288 | 288 | $limit = trim($limit); |
| 289 | 289 | if ($where !== '' && stripos($where, 'WHERE') !== 0) { |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | public function getInsertId($conn = null) |
| 349 | 349 | { |
| 350 | 350 | if (!is_object($conn)) { |
| 351 | - $conn =& $this->conn; |
|
| 351 | + $conn = & $this->conn; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | return $conn->insert_id; |
@@ -357,7 +357,7 @@ discard block |
||
| 357 | 357 | public function getAffectedRows($conn = null) |
| 358 | 358 | { |
| 359 | 359 | if (!is_object($conn)) { |
| 360 | - $conn =& $this->conn; |
|
| 360 | + $conn = & $this->conn; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | return $conn->affected_rows; |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | public function getLastError($conn = null) |
| 367 | 367 | { |
| 368 | 368 | if (!is_object($conn)) { |
| 369 | - $conn =& $this->conn; |
|
| 369 | + $conn = & $this->conn; |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | return $conn->error; |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | { |
| 387 | 387 | $out = false; |
| 388 | 388 | if (is_object($ds)) { |
| 389 | - switch($mode){ |
|
| 389 | + switch ($mode) { |
|
| 390 | 390 | case 'assoc': |
| 391 | 391 | $out = $ds->fetch_assoc(); |
| 392 | 392 | break; |
@@ -304,7 +304,8 @@ discard block |
||
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | public function save($fields, $table, $where = '') |
| 307 | - { // This is similar to "replace into table". |
|
| 307 | + { |
|
| 308 | +// This is similar to "replace into table". |
|
| 308 | 309 | |
| 309 | 310 | if ($where === '') { |
| 310 | 311 | $mode = 'insert'; |
@@ -386,7 +387,7 @@ discard block |
||
| 386 | 387 | { |
| 387 | 388 | $out = false; |
| 388 | 389 | if (is_object($ds)) { |
| 389 | - switch($mode){ |
|
| 390 | + switch($mode) { |
|
| 390 | 391 | case 'assoc': |
| 391 | 392 | $out = $ds->fetch_assoc(); |
| 392 | 393 | break; |
@@ -190,13 +190,13 @@ discard block |
||
| 190 | 190 | $orderby = trim($orderby); |
| 191 | 191 | $limit = trim($limit); |
| 192 | 192 | if ($where !== '' && stripos($where, 'WHERE') !== 0) { |
| 193 | - $where = "WHERE {$where}"; |
|
| 193 | + $where = "where {$where}"; |
|
| 194 | 194 | } |
| 195 | 195 | if ($orderby !== '' && stripos($orderby, 'ORDER BY') !== 0) { |
| 196 | 196 | $orderby = "ORDER BY {$orderby}"; |
| 197 | 197 | } |
| 198 | 198 | if ($limit !== '' && stripos($limit, 'LIMIT') !== 0) { |
| 199 | - $limit = "LIMIT {$limit}"; |
|
| 199 | + $limit = "limit {$limit}"; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | return $this->query("DELETE FROM {$from} {$where} {$orderby} {$limit}"); |
@@ -228,16 +228,16 @@ discard block |
||
| 228 | 228 | $orderby = trim($orderby); |
| 229 | 229 | $limit = trim($limit); |
| 230 | 230 | if ($where !== '' && stripos($where, 'WHERE') !== 0) { |
| 231 | - $where = "WHERE {$where}"; |
|
| 231 | + $where = "where {$where}"; |
|
| 232 | 232 | } |
| 233 | 233 | if ($orderby !== '' && stripos($orderby, 'ORDER') !== 0) { |
| 234 | 234 | $orderby = "ORDER BY {$orderby}"; |
| 235 | 235 | } |
| 236 | 236 | if ($limit !== '' && stripos($limit, 'LIMIT') !== 0) { |
| 237 | - $limit = "LIMIT {$limit}"; |
|
| 237 | + $limit = "limit {$limit}"; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - return $this->query("SELECT {$fields} FROM {$from} {$where} {$orderby} {$limit}"); |
|
| 240 | + return $this->query("select {$fields} FROM {$from} {$where} {$orderby} {$limit}"); |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | public function update($fields, $table, $where = "") |
@@ -260,10 +260,10 @@ discard block |
||
| 260 | 260 | } |
| 261 | 261 | $where = trim($where); |
| 262 | 262 | if ($where !== '' && stripos($where, 'WHERE') !== 0) { |
| 263 | - $where = "WHERE {$where}"; |
|
| 263 | + $where = "where {$where}"; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - return $this->query("UPDATE {$table} SET {$fields} {$where}"); |
|
| 266 | + return $this->query("update {$table} SET {$fields} {$where}"); |
|
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | |
@@ -287,10 +287,10 @@ discard block |
||
| 287 | 287 | $where = trim($where); |
| 288 | 288 | $limit = trim($limit); |
| 289 | 289 | if ($where !== '' && stripos($where, 'WHERE') !== 0) { |
| 290 | - $where = "WHERE {$where}"; |
|
| 290 | + $where = "where {$where}"; |
|
| 291 | 291 | } |
| 292 | 292 | if ($limit !== '' && stripos($limit, 'LIMIT') !== 0) { |
| 293 | - $limit = "LIMIT {$limit}"; |
|
| 293 | + $limit = "limit {$limit}"; |
|
| 294 | 294 | } |
| 295 | 295 | $rt = $this->query("INSERT INTO {$intotable} {$fields} SELECT {$fromfields} FROM {$fromtable} {$where} {$limit}"); |
| 296 | 296 | } |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | |
| 540 | 540 | public function truncate($table_name) |
| 541 | 541 | { |
| 542 | - $rs = $this->query("TRUNCATE {$table_name}"); |
|
| 542 | + $rs = $this->query("truncate {$table_name}"); |
|
| 543 | 543 | |
| 544 | 544 | return $rs; |
| 545 | 545 | } |
@@ -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 | } |
@@ -16,18 +16,18 @@ discard block |
||
| 16 | 16 | { |
| 17 | 17 | global $modx; |
| 18 | 18 | |
| 19 | - if(!defined('MODX_BASE_PATH')) return false; |
|
| 19 | + if (!defined('MODX_BASE_PATH')) return false; |
|
| 20 | 20 | $this->exportstart = $this->get_mtime(); |
| 21 | 21 | $this->count = 0; |
| 22 | 22 | $this->setUrlMode(); |
| 23 | 23 | $this->generate_mode = 'crawl'; |
| 24 | - $this->targetDir = $modx->config['base_path'] . 'temp/export'; |
|
| 25 | - if(!isset($this->total)) $this->getTotal(); |
|
| 24 | + $this->targetDir = $modx->config['base_path'].'temp/export'; |
|
| 25 | + if (!isset($this->total)) $this->getTotal(); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public function setExportDir($dir) |
| 29 | 29 | { |
| 30 | - $dir = str_replace('\\','/',$dir); |
|
| 30 | + $dir = str_replace('\\', '/', $dir); |
|
| 31 | 31 | $dir = rtrim($dir, '/'); |
| 32 | 32 | $this->targetDir = $dir; |
| 33 | 33 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | { |
| 45 | 45 | global $modx; |
| 46 | 46 | |
| 47 | - if($modx->config['friendly_urls']==0) |
|
| 47 | + if ($modx->config['friendly_urls'] == 0) |
|
| 48 | 48 | { |
| 49 | 49 | $modx->config['friendly_urls'] = 1; |
| 50 | 50 | $modx->config['use_alias_path'] = 1; |
@@ -53,13 +53,13 @@ discard block |
||
| 53 | 53 | $modx->config['make_folders'] = '1'; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - public function getTotal($ignore_ids='', $noncache='0') |
|
| 56 | + public function getTotal($ignore_ids = '', $noncache = '0') |
|
| 57 | 57 | { |
| 58 | 58 | global $modx; |
| 59 | 59 | $tbl_site_content = $modx->getFullTableName('site_content'); |
| 60 | 60 | |
| 61 | 61 | $ignore_ids = array_filter(array_map('intval', explode(',', $ignore_ids))); |
| 62 | - if(count($ignore_ids)>0) |
|
| 62 | + if (count($ignore_ids) > 0) |
|
| 63 | 63 | { |
| 64 | 64 | $ignore_ids = "AND NOT id IN ('".implode("','", $ignore_ids)."')"; |
| 65 | 65 | } else { |
@@ -70,72 +70,72 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | $noncache = ($noncache == 1) ? '' : 'AND cacheable=1'; |
| 72 | 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); |
|
| 73 | + $rs = $modx->db->select('count(id)', $tbl_site_content, $where); |
|
| 74 | 74 | $this->total = $modx->db->getValue($rs); |
| 75 | 75 | return $this->total; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - public function removeDirectoryAll($directory='') |
|
| 78 | + public function removeDirectoryAll($directory = '') |
|
| 79 | 79 | { |
| 80 | 80 | $rs = false; |
| 81 | - if(empty($directory)) $directory = $this->targetDir; |
|
| 82 | - $directory = rtrim($directory,'/'); |
|
| 81 | + if (empty($directory)) $directory = $this->targetDir; |
|
| 82 | + $directory = rtrim($directory, '/'); |
|
| 83 | 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; |
|
| 84 | + if (empty($directory)) return false; |
|
| 85 | + if (strpos($directory, MODX_BASE_PATH) === false) return $rs; |
|
| 86 | 86 | |
| 87 | - if(!is_dir($directory)) return $rs; |
|
| 88 | - elseif(!is_readable($directory)) return $rs; |
|
| 87 | + if (!is_dir($directory)) return $rs; |
|
| 88 | + elseif (!is_readable($directory)) return $rs; |
|
| 89 | 89 | else |
| 90 | 90 | { |
| 91 | - $files = glob($directory . '/*'); |
|
| 92 | - if(!empty($files)) |
|
| 91 | + $files = glob($directory.'/*'); |
|
| 92 | + if (!empty($files)) |
|
| 93 | 93 | { |
| 94 | - foreach($files as $path) |
|
| 94 | + foreach ($files as $path) |
|
| 95 | 95 | { |
| 96 | 96 | $rs = is_dir($path) ? $this->removeDirectoryAll($path) : unlink($path); |
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | - if($directory !== $this->targetDir) $rs = rmdir($directory); |
|
| 100 | + if ($directory !== $this->targetDir) $rs = rmdir($directory); |
|
| 101 | 101 | |
| 102 | 102 | return $rs; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | public function makeFile($docid, $filepath) |
| 106 | 106 | { |
| 107 | - global $modx,$_lang; |
|
| 107 | + global $modx, $_lang; |
|
| 108 | 108 | $file_permission = octdec($modx->config['new_file_permissions']); |
| 109 | - if($this->generate_mode==='direct') |
|
| 109 | + if ($this->generate_mode === 'direct') |
|
| 110 | 110 | { |
| 111 | 111 | $back_lang = $_lang; |
| 112 | 112 | $src = $modx->executeParser($docid); |
| 113 | 113 | |
| 114 | 114 | $_lang = $back_lang; |
| 115 | 115 | } |
| 116 | - else $src = $this->curl_get_contents(MODX_SITE_URL . "index.php?id={$docid}"); |
|
| 116 | + else $src = $this->curl_get_contents(MODX_SITE_URL."index.php?id={$docid}"); |
|
| 117 | 117 | |
| 118 | 118 | |
| 119 | - if($src !== false) |
|
| 119 | + if ($src !== false) |
|
| 120 | 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); |
|
| 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 | 124 | |
| 125 | - if($result !== false) return 'success'; |
|
| 125 | + if ($result !== false) return 'success'; |
|
| 126 | 126 | else return 'failed_no_write'; |
| 127 | 127 | } |
| 128 | 128 | else return 'failed_no_retrieve'; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - public function getFileName($docid, $alias='', $prefix, $suffix) |
|
| 131 | + public function getFileName($docid, $alias = '', $prefix, $suffix) |
|
| 132 | 132 | { |
| 133 | 133 | global $modx; |
| 134 | 134 | |
| 135 | - if($alias==='') $filename = $prefix.$docid.$suffix; |
|
| 135 | + if ($alias === '') $filename = $prefix.$docid.$suffix; |
|
| 136 | 136 | else |
| 137 | 137 | { |
| 138 | - if($modx->config['suffix_mode']==='1' && strpos($alias, '.')!==false) |
|
| 138 | + if ($modx->config['suffix_mode'] === '1' && strpos($alias, '.') !== false) |
|
| 139 | 139 | { |
| 140 | 140 | $suffix = ''; |
| 141 | 141 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | return $filename; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - public function run($parent=0) |
|
| 147 | + public function run($parent = 0) |
|
| 148 | 148 | { |
| 149 | 149 | global $_lang; |
| 150 | 150 | global $modx; |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | $tbl_site_content = $modx->getFullTableName('site_content'); |
| 153 | 153 | |
| 154 | 154 | $ignore_ids = $this->ignore_ids; |
| 155 | - $dirpath = $this->targetDir . '/'; |
|
| 155 | + $dirpath = $this->targetDir.'/'; |
|
| 156 | 156 | |
| 157 | 157 | $prefix = $modx->config['friendly_url_prefix']; |
| 158 | 158 | $suffix = $modx->config['friendly_url_suffix']; |
@@ -162,36 +162,36 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | $ph['status'] = 'fail'; |
| 164 | 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); |
|
| 165 | + $ph['msg2'] = $_lang["export_site_failed_no_write"].' - '.$dirpath; |
|
| 166 | + $msg_failed_no_write = $this->parsePlaceholder($tpl, $ph); |
|
| 167 | 167 | |
| 168 | 168 | $ph['msg2'] = $_lang["export_site_failed_no_retrieve"]; |
| 169 | - $msg_failed_no_retrieve = $this->parsePlaceholder($tpl,$ph); |
|
| 169 | + $msg_failed_no_retrieve = $this->parsePlaceholder($tpl, $ph); |
|
| 170 | 170 | |
| 171 | 171 | $ph['status'] = 'success'; |
| 172 | 172 | $ph['msg1'] = $_lang['export_site_success']; |
| 173 | 173 | $ph['msg2'] = ''; |
| 174 | - $msg_success = $this->parsePlaceholder($tpl,$ph); |
|
| 174 | + $msg_success = $this->parsePlaceholder($tpl, $ph); |
|
| 175 | 175 | |
| 176 | 176 | $ph['msg2'] = $_lang['export_site_success_skip_doc']; |
| 177 | - $msg_success_skip_doc = $this->parsePlaceholder($tpl,$ph); |
|
| 177 | + $msg_success_skip_doc = $this->parsePlaceholder($tpl, $ph); |
|
| 178 | 178 | |
| 179 | 179 | $ph['msg2'] = $_lang['export_site_success_skip_dir']; |
| 180 | - $msg_success_skip_dir = $this->parsePlaceholder($tpl,$ph); |
|
| 180 | + $msg_success_skip_dir = $this->parsePlaceholder($tpl, $ph); |
|
| 181 | 181 | |
| 182 | 182 | $fields = "id, alias, pagetitle, isfolder, (content = '' AND template = 0) AS wasNull, published"; |
| 183 | - $noncache = $_POST['includenoncache']==1 ? '' : 'AND cacheable=1'; |
|
| 183 | + $noncache = $_POST['includenoncache'] == 1 ? '' : 'AND cacheable=1'; |
|
| 184 | 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); |
|
| 185 | + $rs = $modx->db->select($fields, $tbl_site_content, $where); |
|
| 186 | 186 | |
| 187 | 187 | $ph = array(); |
| 188 | - $ph['total'] = $this->total; |
|
| 188 | + $ph['total'] = $this->total; |
|
| 189 | 189 | $folder_permission = octdec($modx->config['new_folder_permissions']); |
| 190 | - while($row = $modx->db->getRow($rs)) |
|
| 190 | + while ($row = $modx->db->getRow($rs)) |
|
| 191 | 191 | { |
| 192 | 192 | $this->count++; |
| 193 | 193 | $filename = ''; |
| 194 | - $row['count'] = $this->count; |
|
| 194 | + $row['count'] = $this->count; |
|
| 195 | 195 | $row['url'] = $modx->makeUrl($row['id']); |
| 196 | 196 | |
| 197 | 197 | if (!$row['wasNull']) |
@@ -200,10 +200,10 @@ discard block |
||
| 200 | 200 | $filename = $dirpath.$docname; |
| 201 | 201 | if (!is_file($filename)) |
| 202 | 202 | { |
| 203 | - if($row['published']==='1') |
|
| 203 | + if ($row['published'] === '1') |
|
| 204 | 204 | { |
| 205 | 205 | $status = $this->makeFile($row['id'], $filename); |
| 206 | - switch($status) |
|
| 206 | + switch ($status) |
|
| 207 | 207 | { |
| 208 | 208 | case 'failed_no_write' : |
| 209 | 209 | $row['status'] = $msg_failed_no_write; |
@@ -225,11 +225,11 @@ discard block |
||
| 225 | 225 | $row['status'] = $msg_success_skip_dir; |
| 226 | 226 | $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row); |
| 227 | 227 | } |
| 228 | - if ($row['isfolder']==='1' && ($modx->config['suffix_mode']!=='1' || strpos($row['alias'],'.')===false)) |
|
| 228 | + if ($row['isfolder'] === '1' && ($modx->config['suffix_mode'] !== '1' || strpos($row['alias'], '.') === false)) |
|
| 229 | 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; |
|
| 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 | 233 | if (!is_dir($dir_path)) |
| 234 | 234 | { |
| 235 | 235 | if (is_file($dir_path)) @unlink($dir_path); |
@@ -239,9 +239,9 @@ discard block |
||
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | |
| 242 | - if($modx->config['make_folders']==='1' && $row['published']==='1') |
|
| 242 | + if ($modx->config['make_folders'] === '1' && $row['published'] === '1') |
|
| 243 | 243 | { |
| 244 | - if( ! empty($filename) && is_file($filename)) rename($filename,$dir_path . '/index.html'); |
|
| 244 | + if (!empty($filename) && is_file($filename)) rename($filename, $dir_path.'/index.html'); |
|
| 245 | 245 | } |
| 246 | 246 | $this->targetDir = $dir_path; |
| 247 | 247 | $this->run($row['id']); |
@@ -250,16 +250,16 @@ discard block |
||
| 250 | 250 | return implode("\n", $this->output); |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - public function curl_get_contents($url, $timeout = 30 ) |
|
| 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); |
| 259 | - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 0 = DO NOT VERIFY AUTHENTICITY OF SSL-CERT |
|
| 260 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 2 = CERT MUST INDICATE BEING CONNECTED TO RIGHT SERVER |
|
| 259 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 0 = DO NOT VERIFY AUTHENTICITY OF SSL-CERT |
|
| 260 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 2 = CERT MUST INDICATE BEING CONNECTED TO RIGHT SERVER |
|
| 261 | 261 | curl_setopt($ch, CURLOPT_HEADER, false); |
| 262 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); |
|
| 262 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 263 | 263 | curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
| 264 | 264 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
| 265 | 265 | $result = curl_exec($ch); |
@@ -267,12 +267,12 @@ discard block |
||
| 267 | 267 | return $result; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - public function parsePlaceholder($tpl,$ph=array()) |
|
| 270 | + public function parsePlaceholder($tpl, $ph = array()) |
|
| 271 | 271 | { |
| 272 | - foreach($ph as $k=>$v) |
|
| 272 | + foreach ($ph as $k=>$v) |
|
| 273 | 273 | { |
| 274 | 274 | $k = "[+{$k}+]"; |
| 275 | - $tpl = str_replace($k,$v,$tpl); |
|
| 275 | + $tpl = str_replace($k, $v, $tpl); |
|
| 276 | 276 | } |
| 277 | 277 | return $tpl; |
| 278 | 278 | } |
@@ -13,27 +13,31 @@ discard block |
||
| 13 | 13 | public $dirCheckCount = 0; |
| 14 | 14 | |
| 15 | 15 | public function __construct() |
| 16 | - { |
|
| 16 | + { |
|
| 17 | 17 | global $modx; |
| 18 | 18 | |
| 19 | - if(!defined('MODX_BASE_PATH')) return false; |
|
| 19 | + if(!defined('MODX_BASE_PATH')) { |
|
| 20 | + return false; |
|
| 21 | + } |
|
| 20 | 22 | $this->exportstart = $this->get_mtime(); |
| 21 | 23 | $this->count = 0; |
| 22 | 24 | $this->setUrlMode(); |
| 23 | 25 | $this->generate_mode = 'crawl'; |
| 24 | 26 | $this->targetDir = $modx->config['base_path'] . 'temp/export'; |
| 25 | - if(!isset($this->total)) $this->getTotal(); |
|
| 27 | + if(!isset($this->total)) { |
|
| 28 | + $this->getTotal(); |
|
| 29 | + } |
|
| 26 | 30 | } |
| 27 | 31 | |
| 28 | 32 | public function setExportDir($dir) |
| 29 | - { |
|
| 33 | + { |
|
| 30 | 34 | $dir = str_replace('\\','/',$dir); |
| 31 | 35 | $dir = rtrim($dir, '/'); |
| 32 | 36 | $this->targetDir = $dir; |
| 33 | 37 | } |
| 34 | 38 | |
| 35 | 39 | public function get_mtime() |
| 36 | - { |
|
| 40 | + { |
|
| 37 | 41 | $mtime = microtime(); |
| 38 | 42 | $mtime = explode(' ', $mtime); |
| 39 | 43 | $mtime = $mtime[1] + $mtime[0]; |
@@ -41,11 +45,10 @@ discard block |
||
| 41 | 45 | } |
| 42 | 46 | |
| 43 | 47 | public function setUrlMode() |
| 44 | - { |
|
| 48 | + { |
|
| 45 | 49 | global $modx; |
| 46 | 50 | |
| 47 | - if($modx->config['friendly_urls']==0) |
|
| 48 | - { |
|
| 51 | + if($modx->config['friendly_urls']==0) { |
|
| 49 | 52 | $modx->config['friendly_urls'] = 1; |
| 50 | 53 | $modx->config['use_alias_path'] = 1; |
| 51 | 54 | $modx->clearCache('full'); |
@@ -54,13 +57,12 @@ discard block |
||
| 54 | 57 | } |
| 55 | 58 | |
| 56 | 59 | public function getTotal($ignore_ids='', $noncache='0') |
| 57 | - { |
|
| 60 | + { |
|
| 58 | 61 | global $modx; |
| 59 | 62 | $tbl_site_content = $modx->getFullTableName('site_content'); |
| 60 | 63 | |
| 61 | 64 | $ignore_ids = array_filter(array_map('intval', explode(',', $ignore_ids))); |
| 62 | - if(count($ignore_ids)>0) |
|
| 63 | - { |
|
| 65 | + if(count($ignore_ids)>0) { |
|
| 64 | 66 | $ignore_ids = "AND NOT id IN ('".implode("','", $ignore_ids)."')"; |
| 65 | 67 | } else { |
| 66 | 68 | $ignore_ids = ''; |
@@ -76,67 +78,80 @@ discard block |
||
| 76 | 78 | } |
| 77 | 79 | |
| 78 | 80 | public function removeDirectoryAll($directory='') |
| 79 | - { |
|
| 81 | + { |
|
| 80 | 82 | $rs = false; |
| 81 | - if(empty($directory)) $directory = $this->targetDir; |
|
| 83 | + if(empty($directory)) { |
|
| 84 | + $directory = $this->targetDir; |
|
| 85 | + } |
|
| 82 | 86 | $directory = rtrim($directory,'/'); |
| 83 | 87 | // 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; |
|
| 88 | + if(empty($directory)) { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + if(strpos($directory,MODX_BASE_PATH)===false) { |
|
| 92 | + return $rs; |
|
| 93 | + } |
|
| 86 | 94 | |
| 87 | - if(!is_dir($directory)) return $rs; |
|
| 88 | - elseif(!is_readable($directory)) return $rs; |
|
| 89 | - else |
|
| 90 | - { |
|
| 95 | + if(!is_dir($directory)) { |
|
| 96 | + return $rs; |
|
| 97 | + } elseif(!is_readable($directory)) { |
|
| 98 | + return $rs; |
|
| 99 | + } else { |
|
| 91 | 100 | $files = glob($directory . '/*'); |
| 92 | - if(!empty($files)) |
|
| 93 | - { |
|
| 94 | - foreach($files as $path) |
|
| 95 | - { |
|
| 101 | + if(!empty($files)) { |
|
| 102 | + foreach($files as $path) { |
|
| 96 | 103 | $rs = is_dir($path) ? $this->removeDirectoryAll($path) : unlink($path); |
| 97 | 104 | } |
| 98 | 105 | } |
| 99 | 106 | } |
| 100 | - if($directory !== $this->targetDir) $rs = rmdir($directory); |
|
| 107 | + if($directory !== $this->targetDir) { |
|
| 108 | + $rs = rmdir($directory); |
|
| 109 | + } |
|
| 101 | 110 | |
| 102 | 111 | return $rs; |
| 103 | 112 | } |
| 104 | 113 | |
| 105 | 114 | public function makeFile($docid, $filepath) |
| 106 | - { |
|
| 115 | + { |
|
| 107 | 116 | global $modx,$_lang; |
| 108 | 117 | $file_permission = octdec($modx->config['new_file_permissions']); |
| 109 | - if($this->generate_mode==='direct') |
|
| 110 | - { |
|
| 118 | + if($this->generate_mode==='direct') { |
|
| 111 | 119 | $back_lang = $_lang; |
| 112 | 120 | $src = $modx->executeParser($docid); |
| 113 | 121 | |
| 114 | 122 | $_lang = $back_lang; |
| 123 | + } else { |
|
| 124 | + $src = $this->curl_get_contents(MODX_SITE_URL . "index.php?id={$docid}"); |
|
| 115 | 125 | } |
| 116 | - else $src = $this->curl_get_contents(MODX_SITE_URL . "index.php?id={$docid}"); |
|
| 117 | 126 | |
| 118 | 127 | |
| 119 | - if($src !== false) |
|
| 120 | - { |
|
| 121 | - if($this->repl_before!==$this->repl_after) $src = str_replace($this->repl_before,$this->repl_after,$src); |
|
| 128 | + if($src !== false) { |
|
| 129 | + if($this->repl_before!==$this->repl_after) { |
|
| 130 | + $src = str_replace($this->repl_before,$this->repl_after,$src); |
|
| 131 | + } |
|
| 122 | 132 | $result = file_put_contents($filepath,$src); |
| 123 | - if($result!==false) @chmod($filepath, $file_permission); |
|
| 133 | + if($result!==false) { |
|
| 134 | + @chmod($filepath, $file_permission); |
|
| 135 | + } |
|
| 124 | 136 | |
| 125 | - if($result !== false) return 'success'; |
|
| 126 | - else return 'failed_no_write'; |
|
| 137 | + if($result !== false) { |
|
| 138 | + return 'success'; |
|
| 139 | + } else { |
|
| 140 | + return 'failed_no_write'; |
|
| 141 | + } |
|
| 142 | + } else { |
|
| 143 | + return 'failed_no_retrieve'; |
|
| 127 | 144 | } |
| 128 | - else return 'failed_no_retrieve'; |
|
| 129 | 145 | } |
| 130 | 146 | |
| 131 | 147 | public function getFileName($docid, $alias='', $prefix, $suffix) |
| 132 | - { |
|
| 148 | + { |
|
| 133 | 149 | global $modx; |
| 134 | 150 | |
| 135 | - if($alias==='') $filename = $prefix.$docid.$suffix; |
|
| 136 | - else |
|
| 137 | - { |
|
| 138 | - if($modx->config['suffix_mode']==='1' && strpos($alias, '.')!==false) |
|
| 139 | - { |
|
| 151 | + if($alias==='') { |
|
| 152 | + $filename = $prefix.$docid.$suffix; |
|
| 153 | + } else { |
|
| 154 | + if($modx->config['suffix_mode']==='1' && strpos($alias, '.')!==false) { |
|
| 140 | 155 | $suffix = ''; |
| 141 | 156 | } |
| 142 | 157 | $filename = $prefix.$alias.$suffix; |
@@ -145,7 +160,7 @@ discard block |
||
| 145 | 160 | } |
| 146 | 161 | |
| 147 | 162 | public function run($parent=0) |
| 148 | - { |
|
| 163 | + { |
|
| 149 | 164 | global $_lang; |
| 150 | 165 | global $modx; |
| 151 | 166 | |
@@ -187,24 +202,20 @@ discard block |
||
| 187 | 202 | $ph = array(); |
| 188 | 203 | $ph['total'] = $this->total; |
| 189 | 204 | $folder_permission = octdec($modx->config['new_folder_permissions']); |
| 190 | - while($row = $modx->db->getRow($rs)) |
|
| 191 | - { |
|
| 205 | + while($row = $modx->db->getRow($rs)) { |
|
| 192 | 206 | $this->count++; |
| 193 | 207 | $filename = ''; |
| 194 | 208 | $row['count'] = $this->count; |
| 195 | 209 | $row['url'] = $modx->makeUrl($row['id']); |
| 196 | 210 | |
| 197 | - if (!$row['wasNull']) |
|
| 198 | - { // needs writing a document |
|
| 211 | + if (!$row['wasNull']) { |
|
| 212 | +// needs writing a document |
|
| 199 | 213 | $docname = $this->getFileName($row['id'], $row['alias'], $prefix, $suffix); |
| 200 | 214 | $filename = $dirpath.$docname; |
| 201 | - if (!is_file($filename)) |
|
| 202 | - { |
|
| 203 | - if($row['published']==='1') |
|
| 204 | - { |
|
| 215 | + if (!is_file($filename)) { |
|
| 216 | + if($row['published']==='1') { |
|
| 205 | 217 | $status = $this->makeFile($row['id'], $filename); |
| 206 | - switch($status) |
|
| 207 | - { |
|
| 218 | + switch($status) { |
|
| 208 | 219 | case 'failed_no_write' : |
| 209 | 220 | $row['status'] = $msg_failed_no_write; |
| 210 | 221 | break; |
@@ -214,34 +225,38 @@ discard block |
||
| 214 | 225 | default: |
| 215 | 226 | $row['status'] = $msg_success; |
| 216 | 227 | } |
| 228 | + } else { |
|
| 229 | + $row['status'] = $msg_failed_no_retrieve; |
|
| 217 | 230 | } |
| 218 | - else $row['status'] = $msg_failed_no_retrieve; |
|
| 231 | + } else { |
|
| 232 | + $row['status'] = $msg_success_skip_doc; |
|
| 219 | 233 | } |
| 220 | - else $row['status'] = $msg_success_skip_doc; |
|
| 221 | 234 | $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row); |
| 222 | - } |
|
| 223 | - else |
|
| 224 | - { |
|
| 235 | + } else { |
|
| 225 | 236 | $row['status'] = $msg_success_skip_dir; |
| 226 | 237 | $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row); |
| 227 | 238 | } |
| 228 | - if ($row['isfolder']==='1' && ($modx->config['suffix_mode']!=='1' || strpos($row['alias'],'.')===false)) |
|
| 229 | - { // needs making a folder |
|
| 239 | + if ($row['isfolder']==='1' && ($modx->config['suffix_mode']!=='1' || strpos($row['alias'],'.')===false)) { |
|
| 240 | +// needs making a folder |
|
| 230 | 241 | $end_dir = ($row['alias']!=='') ? $row['alias'] : $row['id']; |
| 231 | 242 | $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); |
|
| 243 | + if(strpos($dir_path,MODX_BASE_PATH)===false) { |
|
| 244 | + return FALSE; |
|
| 245 | + } |
|
| 246 | + if (!is_dir($dir_path)) { |
|
| 247 | + if (is_file($dir_path)) { |
|
| 248 | + @unlink($dir_path); |
|
| 249 | + } |
|
| 236 | 250 | mkdir($dir_path); |
| 237 | 251 | @chmod($dir_path, $folder_permission); |
| 238 | 252 | |
| 239 | 253 | } |
| 240 | 254 | |
| 241 | 255 | |
| 242 | - if($modx->config['make_folders']==='1' && $row['published']==='1') |
|
| 243 | - { |
|
| 244 | - if( ! empty($filename) && is_file($filename)) rename($filename,$dir_path . '/index.html'); |
|
| 256 | + if($modx->config['make_folders']==='1' && $row['published']==='1') { |
|
| 257 | + if( ! empty($filename) && is_file($filename)) { |
|
| 258 | + rename($filename,$dir_path . '/index.html'); |
|
| 259 | + } |
|
| 245 | 260 | } |
| 246 | 261 | $this->targetDir = $dir_path; |
| 247 | 262 | $this->run($row['id']); |
@@ -252,7 +267,9 @@ discard block |
||
| 252 | 267 | |
| 253 | 268 | public function curl_get_contents($url, $timeout = 30 ) |
| 254 | 269 | { |
| 255 | - if(!function_exists('curl_init')) return @file_get_contents($url); |
|
| 270 | + if(!function_exists('curl_init')) { |
|
| 271 | + return @file_get_contents($url); |
|
| 272 | + } |
|
| 256 | 273 | |
| 257 | 274 | $ch = curl_init(); |
| 258 | 275 | curl_setopt($ch, CURLOPT_URL, $url); |
@@ -269,8 +286,7 @@ discard block |
||
| 269 | 286 | |
| 270 | 287 | public function parsePlaceholder($tpl,$ph=array()) |
| 271 | 288 | { |
| 272 | - foreach($ph as $k=>$v) |
|
| 273 | - { |
|
| 289 | + foreach($ph as $k=>$v) { |
|
| 274 | 290 | $k = "[+{$k}+]"; |
| 275 | 291 | $tpl = str_replace($k,$v,$tpl); |
| 276 | 292 | } |
@@ -229,7 +229,7 @@ |
||
| 229 | 229 | { // needs making a folder |
| 230 | 230 | $end_dir = ($row['alias']!=='') ? $row['alias'] : $row['id']; |
| 231 | 231 | $dir_path = $dirpath . $end_dir; |
| 232 | - if(strpos($dir_path,MODX_BASE_PATH)===false) return FALSE; |
|
| 232 | + if(strpos($dir_path,MODX_BASE_PATH)===false) return false; |
|
| 233 | 233 | if (!is_dir($dir_path)) |
| 234 | 234 | { |
| 235 | 235 | if (is_file($dir_path)) @unlink($dir_path); |
@@ -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 | } |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | * |
| 9 | 9 | * @author Jason Coward <[email protected]> (MODX) |
| 10 | 10 | */ |
| 11 | -class MakeTable { |
|
| 11 | +class MakeTable{ |
|
| 12 | 12 | public $actionField; |
| 13 | 13 | public $cellAction; |
| 14 | 14 | public $linkAction; |
@@ -33,26 +33,26 @@ discard block |
||
| 33 | 33 | public $fieldHeaders; |
| 34 | 34 | public $extra; |
| 35 | 35 | |
| 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= ''; |
|
| 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 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | * |
| 61 | 61 | * @param $value A URL to execute when table cells are clicked. |
| 62 | 62 | */ |
| 63 | - public function setCellAction($value) { |
|
| 64 | - $this->cellAction= $this->prepareLink($value); |
|
| 63 | + public function setCellAction($value){ |
|
| 64 | + $this->cellAction = $this->prepareLink($value); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @param $value A URL to execute when text within table cells are clicked. |
| 71 | 71 | */ |
| 72 | - public function setLinkAction($value) { |
|
| 73 | - $this->linkAction= $this->prepareLink($value); |
|
| 72 | + public function setLinkAction($value){ |
|
| 73 | + $this->linkAction = $this->prepareLink($value); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | * |
| 79 | 79 | * @param $value A valid width attribute for the HTML TABLE tag |
| 80 | 80 | */ |
| 81 | - public function setTableWidth($value) { |
|
| 82 | - $this->tableWidth= $value; |
|
| 81 | + public function setTableWidth($value){ |
|
| 82 | + $this->tableWidth = $value; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -87,8 +87,8 @@ discard block |
||
| 87 | 87 | * |
| 88 | 88 | * @param $value A class for the main HTML TABLE. |
| 89 | 89 | */ |
| 90 | - public function setTableClass($value) { |
|
| 91 | - $this->tableClass= $value; |
|
| 90 | + public function setTableClass($value){ |
|
| 91 | + $this->tableClass = $value; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | * |
| 97 | 97 | * @param $value A class for the main HTML TABLE. |
| 98 | 98 | */ |
| 99 | - public function setTableID($value) { |
|
| 100 | - $this->tableID= $value; |
|
| 99 | + public function setTableID($value){ |
|
| 100 | + $this->tableID = $value; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @param $value A class for the table header row. |
| 107 | 107 | */ |
| 108 | - public function setRowHeaderClass($value) { |
|
| 109 | - $this->rowHeaderClass= $value; |
|
| 108 | + public function setRowHeaderClass($value){ |
|
| 109 | + $this->rowHeaderClass = $value; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | * |
| 115 | 115 | * @param $value A class for the table header row. |
| 116 | 116 | */ |
| 117 | - public function setThHeaderClass($value) { |
|
| 118 | - $this->thClass= $value; |
|
| 117 | + public function setThHeaderClass($value){ |
|
| 118 | + $this->thClass = $value; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * @param $value A class for the column header row. |
| 125 | 125 | */ |
| 126 | - public function setColumnHeaderClass($value) { |
|
| 127 | - $this->columnHeaderClass= $value; |
|
| 126 | + public function setColumnHeaderClass($value){ |
|
| 127 | + $this->columnHeaderClass = $value; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | * |
| 133 | 133 | * @param $value A class for regular table rows. |
| 134 | 134 | */ |
| 135 | - public function setRowRegularClass($value) { |
|
| 136 | - $this->rowRegularClass= $value; |
|
| 135 | + public function setRowRegularClass($value){ |
|
| 136 | + $this->rowRegularClass = $value; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -141,8 +141,8 @@ discard block |
||
| 141 | 141 | * |
| 142 | 142 | * @param $value A class for alternate table rows. |
| 143 | 143 | */ |
| 144 | - public function setRowAlternateClass($value) { |
|
| 145 | - $this->rowAlternateClass= $value; |
|
| 144 | + public function setRowAlternateClass($value){ |
|
| 145 | + $this->rowAlternateClass = $value; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -150,8 +150,8 @@ discard block |
||
| 150 | 150 | * |
| 151 | 151 | * @param $value Indicates the INPUT form element type attribute. |
| 152 | 152 | */ |
| 153 | - public function setFormElementType($value) { |
|
| 154 | - $this->formElementType= $value; |
|
| 153 | + public function setFormElementType($value){ |
|
| 154 | + $this->formElementType = $value; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @param $value Indicates the INPUT form element name attribute. |
| 161 | 161 | */ |
| 162 | - public function setFormElementName($value) { |
|
| 163 | - $this->formElementName= $value; |
|
| 162 | + public function setFormElementName($value){ |
|
| 163 | + $this->formElementName = $value; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -169,8 +169,8 @@ discard block |
||
| 169 | 169 | * |
| 170 | 170 | * @param $value Indicates the FORM name attribute. |
| 171 | 171 | */ |
| 172 | - public function setFormName($value) { |
|
| 173 | - $this->formName= $value; |
|
| 172 | + public function setFormName($value){ |
|
| 173 | + $this->formName = $value; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | * |
| 179 | 179 | * @param $value Indicates the FORM action attribute. |
| 180 | 180 | */ |
| 181 | - public function setFormAction($value) { |
|
| 182 | - $this->formAction= $value; |
|
| 181 | + public function setFormAction($value){ |
|
| 182 | + $this->formAction = $value; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -187,8 +187,8 @@ discard block |
||
| 187 | 187 | * |
| 188 | 188 | * @param $value An Array of field keys to exclude from the table. |
| 189 | 189 | */ |
| 190 | - public function setExcludeFields($value) { |
|
| 191 | - $this->excludeFields= $value; |
|
| 190 | + public function setExcludeFields($value){ |
|
| 191 | + $this->excludeFields = $value; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -196,8 +196,8 @@ discard block |
||
| 196 | 196 | * |
| 197 | 197 | * @param $value 'ODD' or 'EVEN' to indicate the alternate row scheme. |
| 198 | 198 | */ |
| 199 | - public function setRowAlternatingScheme($value) { |
|
| 200 | - $this->rowAlternatingScheme= $value; |
|
| 199 | + public function setRowAlternatingScheme($value){ |
|
| 200 | + $this->rowAlternatingScheme = $value; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -206,8 +206,8 @@ discard block |
||
| 206 | 206 | * |
| 207 | 207 | * @param $value The key of the field to add as a query string parameter. |
| 208 | 208 | */ |
| 209 | - public function setActionFieldName($value) { |
|
| 210 | - $this->actionField= $value; |
|
| 209 | + public function setActionFieldName($value){ |
|
| 210 | + $this->actionField = $value; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -216,8 +216,8 @@ discard block |
||
| 216 | 216 | * @param $value An Array of column widths in the order of the keys in the |
| 217 | 217 | * source table array. |
| 218 | 218 | */ |
| 219 | - public function setColumnWidths($widthArray) { |
|
| 220 | - $this->columnWidths= $widthArray; |
|
| 219 | + public function setColumnWidths($widthArray){ |
|
| 220 | + $this->columnWidths = $widthArray; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -225,8 +225,8 @@ discard block |
||
| 225 | 225 | * |
| 226 | 226 | * @param $value Indicates the INPUT form element type attribute. |
| 227 | 227 | */ |
| 228 | - public function setSelectedValues($valueArray) { |
|
| 229 | - $this->selectedValues= $valueArray; |
|
| 228 | + public function setSelectedValues($valueArray){ |
|
| 229 | + $this->selectedValues = $valueArray; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -235,8 +235,8 @@ discard block |
||
| 235 | 235 | * |
| 236 | 236 | * @param $value A string of additional content. |
| 237 | 237 | */ |
| 238 | - public function setExtra($value) { |
|
| 239 | - $this->extra= $value; |
|
| 238 | + public function setExtra($value){ |
|
| 239 | + $this->extra = $value; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -244,10 +244,10 @@ discard block |
||
| 244 | 244 | * |
| 245 | 245 | * @param $columnPosition The index of the column to get the width for. |
| 246 | 246 | */ |
| 247 | - public function getColumnWidth($columnPosition) { |
|
| 248 | - $currentWidth= ''; |
|
| 247 | + public function getColumnWidth($columnPosition){ |
|
| 248 | + $currentWidth = ''; |
|
| 249 | 249 | if (is_array($this->columnWidths)) { |
| 250 | - $currentWidth= $this->columnWidths[$columnPosition] ? ' width="'.$this->columnWidths[$columnPosition].'" ' : ''; |
|
| 250 | + $currentWidth = $this->columnWidths[$columnPosition] ? ' width="'.$this->columnWidths[$columnPosition].'" ' : ''; |
|
| 251 | 251 | } |
| 252 | 252 | return $currentWidth; |
| 253 | 253 | } |
@@ -257,19 +257,19 @@ discard block |
||
| 257 | 257 | * |
| 258 | 258 | * @param $value The position of the current row being rendered. |
| 259 | 259 | */ |
| 260 | - public function determineRowClass($position) { |
|
| 260 | + public function determineRowClass($position){ |
|
| 261 | 261 | switch ($this->rowAlternatingScheme) { |
| 262 | 262 | case 'ODD' : |
| 263 | - $modRemainder= 1; |
|
| 263 | + $modRemainder = 1; |
|
| 264 | 264 | break; |
| 265 | 265 | case 'EVEN' : |
| 266 | - $modRemainder= 0; |
|
| 266 | + $modRemainder = 0; |
|
| 267 | 267 | break; |
| 268 | 268 | } |
| 269 | 269 | if ($position % 2 == $modRemainder) { |
| 270 | - $currentClass= $this->rowRegularClass; |
|
| 270 | + $currentClass = $this->rowRegularClass; |
|
| 271 | 271 | } else { |
| 272 | - $currentClass= $this->rowAlternateClass; |
|
| 272 | + $currentClass = $this->rowAlternateClass; |
|
| 273 | 273 | } |
| 274 | 274 | return ' class="'.$currentClass.'"'; |
| 275 | 275 | } |
@@ -280,9 +280,9 @@ discard block |
||
| 280 | 280 | * |
| 281 | 281 | * @param $value Indicates the INPUT form element type attribute. |
| 282 | 282 | */ |
| 283 | - public function getCellAction($currentActionFieldValue) { |
|
| 283 | + public function getCellAction($currentActionFieldValue){ |
|
| 284 | 284 | if ($this->cellAction) { |
| 285 | - $cellAction= ' onClick="javascript:window.location=\''.$this->cellAction.$this->actionField.'='.urlencode($currentActionFieldValue).'\'" '; |
|
| 285 | + $cellAction = ' onClick="javascript:window.location=\''.$this->cellAction.$this->actionField.'='.urlencode($currentActionFieldValue).'\'" '; |
|
| 286 | 286 | } |
| 287 | 287 | return $cellAction; |
| 288 | 288 | } |
@@ -293,10 +293,10 @@ discard block |
||
| 293 | 293 | * @param $currentActionFieldValue The value to be applied to the link action. |
| 294 | 294 | * @param $value The value of the cell. |
| 295 | 295 | */ |
| 296 | - public function createCellText($currentActionFieldValue, $value) { |
|
| 296 | + public function createCellText($currentActionFieldValue, $value){ |
|
| 297 | 297 | $cell .= $value; |
| 298 | 298 | if ($this->linkAction) { |
| 299 | - $cell= '<a href="'.$this->linkAction.$this->actionField.'='.urlencode($currentActionFieldValue).'">'.$cell.'</a>'; |
|
| 299 | + $cell = '<a href="'.$this->linkAction.$this->actionField.'='.urlencode($currentActionFieldValue).'">'.$cell.'</a>'; |
|
| 300 | 300 | } |
| 301 | 301 | return $cell; |
| 302 | 302 | } |
@@ -305,8 +305,8 @@ discard block |
||
| 305 | 305 | * Sets an option to generate a check all link when checkbox is indicated |
| 306 | 306 | * as the table formElementType. |
| 307 | 307 | */ |
| 308 | - public function setAllOption() { |
|
| 309 | - $this->allOption= 1; |
|
| 308 | + public function setAllOption(){ |
|
| 309 | + $this->allOption = 1; |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | /** |
@@ -314,11 +314,11 @@ discard block |
||
| 314 | 314 | * |
| 315 | 315 | * @param $value Indicates the INPUT form element type attribute. |
| 316 | 316 | */ |
| 317 | - public function prepareLink($link) { |
|
| 317 | + public function prepareLink($link){ |
|
| 318 | 318 | if (strstr($link, '?')) { |
| 319 | - $end= '&'; |
|
| 319 | + $end = '&'; |
|
| 320 | 320 | } else { |
| 321 | - $end= '?'; |
|
| 321 | + $end = '?'; |
|
| 322 | 322 | } |
| 323 | 323 | return $link.$end; |
| 324 | 324 | } |
@@ -333,20 +333,20 @@ discard block |
||
| 333 | 333 | * the $fieldsArray where the values represent the alt heading content |
| 334 | 334 | * for each column. |
| 335 | 335 | */ |
| 336 | - public function create($fieldsArray, $fieldHeadersArray=array(),$linkpage="") { |
|
| 336 | + public function create($fieldsArray, $fieldHeadersArray = array(), $linkpage = ""){ |
|
| 337 | 337 | global $_lang; |
| 338 | 338 | if (is_array($fieldsArray)) { |
| 339 | - $i= 0; |
|
| 339 | + $i = 0; |
|
| 340 | 340 | foreach ($fieldsArray as $fieldName => $fieldValue) { |
| 341 | 341 | $table .= "\t<tr".$this->determineRowClass($i).">\n"; |
| 342 | - $currentActionFieldValue= $fieldValue[$this->actionField]; |
|
| 342 | + $currentActionFieldValue = $fieldValue[$this->actionField]; |
|
| 343 | 343 | if (is_array($this->selectedValues)) { |
| 344 | - $isChecked= array_search($currentActionFieldValue, $this->selectedValues)===false? 0 : 1; |
|
| 344 | + $isChecked = array_search($currentActionFieldValue, $this->selectedValues) === false ? 0 : 1; |
|
| 345 | 345 | } else { |
| 346 | - $isChecked= false; |
|
| 346 | + $isChecked = false; |
|
| 347 | 347 | } |
| 348 | 348 | $table .= $this->addFormField($currentActionFieldValue, $isChecked); |
| 349 | - $colPosition= 0; |
|
| 349 | + $colPosition = 0; |
|
| 350 | 350 | foreach ($fieldValue as $key => $value) { |
| 351 | 351 | if (!in_array($key, $this->excludeFields)) { |
| 352 | 352 | $table .= "\t\t<td".$this->getCellAction($currentActionFieldValue).">"; |
@@ -354,20 +354,20 @@ discard block |
||
| 354 | 354 | $table .= "</td>\n"; |
| 355 | 355 | if ($i == 0) { |
| 356 | 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"; |
|
| 357 | + $header .= "\t\t<th style=\"width:32px\" ".($this->thClass ? 'class="'.$this->thClass.'"' : '').">".($this->allOption ? '<a href="javascript:clickAll()">all</a>' : '')."</th>\n"; |
|
| 358 | 358 | } |
| 359 | - $headerText= array_key_exists($key, $fieldHeadersArray)? $fieldHeadersArray[$key]: $key; |
|
| 359 | + $headerText = array_key_exists($key, $fieldHeadersArray) ? $fieldHeadersArray[$key] : $key; |
|
| 360 | 360 | $header .= "\t\t<th".$this->getColumnWidth($colPosition).($this->thClass ? ' class="'.$this->thClass.'" ' : '').">".$headerText."</th>\n"; |
| 361 | 361 | } |
| 362 | - $colPosition ++; |
|
| 362 | + $colPosition++; |
|
| 363 | 363 | } |
| 364 | 364 | } |
| 365 | - $i ++; |
|
| 365 | + $i++; |
|
| 366 | 366 | $table .= "\t</tr>\n"; |
| 367 | 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"; |
|
| 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 | 369 | if ($this->formElementType) { |
| 370 | - $table= "\n".'<form id="'.$this->formName.'" name="'.$this->formName.'" action="'.$this->formAction.'" method="POST">'.$table; |
|
| 370 | + $table = "\n".'<form id="'.$this->formName.'" name="'.$this->formName.'" action="'.$this->formAction.'" method="POST">'.$table; |
|
| 371 | 371 | } |
| 372 | 372 | if (strlen($this->pageNav) > 1) {//changed to display the pagination if exists. |
| 373 | 373 | /* commented this part because of cookie |
@@ -402,9 +402,9 @@ discard block |
||
| 402 | 402 | } |
| 403 | 403 | if ($this->formElementType) { |
| 404 | 404 | if ($this->extra) { |
| 405 | - $table.= "\n".$this->extra."\n"; |
|
| 405 | + $table .= "\n".$this->extra."\n"; |
|
| 406 | 406 | } |
| 407 | - $table.= "\n".'</form>'."\n"; |
|
| 407 | + $table .= "\n".'</form>'."\n"; |
|
| 408 | 408 | } |
| 409 | 409 | return $table; |
| 410 | 410 | } |
@@ -416,36 +416,36 @@ discard block |
||
| 416 | 416 | * @param $numRecords The number of records to show per page. |
| 417 | 417 | * @param $qs An optional query string to be appended to the paging links |
| 418 | 418 | */ |
| 419 | - public function createPagingNavigation($numRecords, $qs='') { |
|
| 419 | + public function createPagingNavigation($numRecords, $qs = ''){ |
|
| 420 | 420 | global $_lang; |
| 421 | - $currentPage= (is_numeric($_GET['page']) ? $_GET['page'] : 1); |
|
| 422 | - $numPages= ceil($numRecords / MAX_DISPLAY_RECORDS_NUM); |
|
| 421 | + $currentPage = (is_numeric($_GET['page']) ? $_GET['page'] : 1); |
|
| 422 | + $numPages = ceil($numRecords / MAX_DISPLAY_RECORDS_NUM); |
|
| 423 | 423 | if ($numPages > 1) { |
| 424 | - $currentURL= empty($qs)? '': '?'.$qs; |
|
| 424 | + $currentURL = empty($qs) ? '' : '?'.$qs; |
|
| 425 | 425 | if ($currentPage > 6) { |
| 426 | 426 | $nav .= $this->createPageLink($currentURL, 1, $_lang["pagination_table_first"]); |
| 427 | 427 | } |
| 428 | 428 | if ($currentPage != 1) { |
| 429 | - $nav .= $this->createPageLink($currentURL, $currentPage -1, '<<'); |
|
| 429 | + $nav .= $this->createPageLink($currentURL, $currentPage - 1, '<<'); |
|
| 430 | 430 | } |
| 431 | - $offset= -4 + ($currentPage < 5 ? (5 - $currentPage) : 0); |
|
| 432 | - $i= 1; |
|
| 431 | + $offset = -4 + ($currentPage < 5 ? (5 - $currentPage) : 0); |
|
| 432 | + $i = 1; |
|
| 433 | 433 | while ($i < 10 && ($currentPage + $offset <= $numPages)) { |
| 434 | 434 | if ($currentPage == $currentPage + $offset) |
| 435 | 435 | $nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset, true); |
| 436 | 436 | else |
| 437 | 437 | $nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset); |
| 438 | - $i ++; |
|
| 439 | - $offset ++; |
|
| 438 | + $i++; |
|
| 439 | + $offset++; |
|
| 440 | 440 | } |
| 441 | 441 | if ($currentPage < $numPages) { |
| 442 | - $nav .= $this->createPageLink($currentURL, $currentPage +1, '>>'); |
|
| 442 | + $nav .= $this->createPageLink($currentURL, $currentPage + 1, '>>'); |
|
| 443 | 443 | } |
| 444 | 444 | if ($currentPage != $numPages) { |
| 445 | 445 | $nav .= $this->createPageLink($currentURL, $numPages, $_lang["pagination_table_last"]); |
| 446 | 446 | } |
| 447 | 447 | } |
| 448 | - $this->pageNav= ' '.$nav; |
|
| 448 | + $this->pageNav = ' '.$nav; |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /** |
@@ -457,13 +457,13 @@ discard block |
||
| 457 | 457 | * @param $currentPage Indicates if the link is to the current page. |
| 458 | 458 | * @param $qs And optional query string to be appended to the link. |
| 459 | 459 | */ |
| 460 | - public function createPageLink($link='', $pageNum, $displayText, $currentPage=false, $qs='') { |
|
| 460 | + public function createPageLink($link = '', $pageNum, $displayText, $currentPage = false, $qs = ''){ |
|
| 461 | 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"; |
|
| 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 | 467 | return $nav; |
| 468 | 468 | } |
| 469 | 469 | |
@@ -474,10 +474,10 @@ discard block |
||
| 474 | 474 | * @param $isChecked Indicates if the checked attribute should apply to the |
| 475 | 475 | * element. |
| 476 | 476 | */ |
| 477 | - public function addFormField($value, $isChecked) { |
|
| 477 | + public function addFormField($value, $isChecked){ |
|
| 478 | 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"; |
|
| 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 | 481 | } |
| 482 | 482 | return $field; |
| 483 | 483 | } |
@@ -486,9 +486,9 @@ discard block |
||
| 486 | 486 | * Generates the proper LIMIT clause for queries to retrieve paged results in |
| 487 | 487 | * a MakeTable $fieldsArray. |
| 488 | 488 | */ |
| 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; |
|
| 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 | 492 | return $limitClause; |
| 493 | 493 | } |
| 494 | 494 | |
@@ -498,12 +498,12 @@ discard block |
||
| 498 | 498 | * |
| 499 | 499 | * @param $natural_order If true, the results are returned in natural order. |
| 500 | 500 | */ |
| 501 | - public function handleSorting($natural_order=false) { |
|
| 502 | - $orderByClause= ''; |
|
| 501 | + public function handleSorting($natural_order = false){ |
|
| 502 | + $orderByClause = ''; |
|
| 503 | 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 . ' ': ""; |
|
| 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 | 507 | } |
| 508 | 508 | return $orderbyClause; |
| 509 | 509 | } |
@@ -516,15 +516,15 @@ discard block |
||
| 516 | 516 | * @param $text The text for the link (e.g. table column header). |
| 517 | 517 | * @param $qs An optional query string to append to the order by link. |
| 518 | 518 | */ |
| 519 | - public function prepareOrderByLink($key, $text, $qs='') { |
|
| 519 | + public function prepareOrderByLink($key, $text, $qs = ''){ |
|
| 520 | 520 | global $modx; |
| 521 | 521 | if (!empty($_GET['orderdir'])) { |
| 522 | - $orderDir= strtolower($_GET['orderdir'])=='desc'? '&orderdir=asc': '&orderdir=desc'; |
|
| 522 | + $orderDir = strtolower($_GET['orderdir']) == 'desc' ? '&orderdir=asc' : '&orderdir=desc'; |
|
| 523 | 523 | } else { |
| 524 | - $orderDir= '&orderdir=asc'; |
|
| 524 | + $orderDir = '&orderdir=asc'; |
|
| 525 | 525 | } |
| 526 | 526 | if (!empty($qs)) { |
| 527 | - if (!strrpos($qs, '&')==strlen($qs)-1) $qs.= '&'; |
|
| 527 | + if (!strrpos($qs, '&') == strlen($qs) - 1) $qs .= '&'; |
|
| 528 | 528 | } |
| 529 | 529 | return '<a href="[~'.$modx->documentIdentifier.'~]?'.$qs.'orderby='.$key.$orderDir.'">'.$text.'</a>'; |
| 530 | 530 | } |
@@ -8,7 +8,8 @@ discard block |
||
| 8 | 8 | * |
| 9 | 9 | * @author Jason Coward <[email protected]> (MODX) |
| 10 | 10 | */ |
| 11 | -class MakeTable { |
|
| 11 | +class MakeTable |
|
| 12 | +{ |
|
| 12 | 13 | public $actionField; |
| 13 | 14 | public $cellAction; |
| 14 | 15 | public $linkAction; |
@@ -33,7 +34,8 @@ discard block |
||
| 33 | 34 | public $fieldHeaders; |
| 34 | 35 | public $extra; |
| 35 | 36 | |
| 36 | - public function __construct() { |
|
| 37 | + public function __construct() |
|
| 38 | + { |
|
| 37 | 39 | $this->fieldHeaders= array(); |
| 38 | 40 | $this->excludeFields= array(); |
| 39 | 41 | $this->actionField= ''; |
@@ -60,7 +62,8 @@ discard block |
||
| 60 | 62 | * |
| 61 | 63 | * @param $value A URL to execute when table cells are clicked. |
| 62 | 64 | */ |
| 63 | - public function setCellAction($value) { |
|
| 65 | + public function setCellAction($value) |
|
| 66 | + { |
|
| 64 | 67 | $this->cellAction= $this->prepareLink($value); |
| 65 | 68 | } |
| 66 | 69 | |
@@ -69,7 +72,8 @@ discard block |
||
| 69 | 72 | * |
| 70 | 73 | * @param $value A URL to execute when text within table cells are clicked. |
| 71 | 74 | */ |
| 72 | - public function setLinkAction($value) { |
|
| 75 | + public function setLinkAction($value) |
|
| 76 | + { |
|
| 73 | 77 | $this->linkAction= $this->prepareLink($value); |
| 74 | 78 | } |
| 75 | 79 | |
@@ -78,7 +82,8 @@ discard block |
||
| 78 | 82 | * |
| 79 | 83 | * @param $value A valid width attribute for the HTML TABLE tag |
| 80 | 84 | */ |
| 81 | - public function setTableWidth($value) { |
|
| 85 | + public function setTableWidth($value) |
|
| 86 | + { |
|
| 82 | 87 | $this->tableWidth= $value; |
| 83 | 88 | } |
| 84 | 89 | |
@@ -87,7 +92,8 @@ discard block |
||
| 87 | 92 | * |
| 88 | 93 | * @param $value A class for the main HTML TABLE. |
| 89 | 94 | */ |
| 90 | - public function setTableClass($value) { |
|
| 95 | + public function setTableClass($value) |
|
| 96 | + { |
|
| 91 | 97 | $this->tableClass= $value; |
| 92 | 98 | } |
| 93 | 99 | |
@@ -96,7 +102,8 @@ discard block |
||
| 96 | 102 | * |
| 97 | 103 | * @param $value A class for the main HTML TABLE. |
| 98 | 104 | */ |
| 99 | - public function setTableID($value) { |
|
| 105 | + public function setTableID($value) |
|
| 106 | + { |
|
| 100 | 107 | $this->tableID= $value; |
| 101 | 108 | } |
| 102 | 109 | |
@@ -105,7 +112,8 @@ discard block |
||
| 105 | 112 | * |
| 106 | 113 | * @param $value A class for the table header row. |
| 107 | 114 | */ |
| 108 | - public function setRowHeaderClass($value) { |
|
| 115 | + public function setRowHeaderClass($value) |
|
| 116 | + { |
|
| 109 | 117 | $this->rowHeaderClass= $value; |
| 110 | 118 | } |
| 111 | 119 | |
@@ -114,7 +122,8 @@ discard block |
||
| 114 | 122 | * |
| 115 | 123 | * @param $value A class for the table header row. |
| 116 | 124 | */ |
| 117 | - public function setThHeaderClass($value) { |
|
| 125 | + public function setThHeaderClass($value) |
|
| 126 | + { |
|
| 118 | 127 | $this->thClass= $value; |
| 119 | 128 | } |
| 120 | 129 | |
@@ -123,7 +132,8 @@ discard block |
||
| 123 | 132 | * |
| 124 | 133 | * @param $value A class for the column header row. |
| 125 | 134 | */ |
| 126 | - public function setColumnHeaderClass($value) { |
|
| 135 | + public function setColumnHeaderClass($value) |
|
| 136 | + { |
|
| 127 | 137 | $this->columnHeaderClass= $value; |
| 128 | 138 | } |
| 129 | 139 | |
@@ -132,7 +142,8 @@ discard block |
||
| 132 | 142 | * |
| 133 | 143 | * @param $value A class for regular table rows. |
| 134 | 144 | */ |
| 135 | - public function setRowRegularClass($value) { |
|
| 145 | + public function setRowRegularClass($value) |
|
| 146 | + { |
|
| 136 | 147 | $this->rowRegularClass= $value; |
| 137 | 148 | } |
| 138 | 149 | |
@@ -141,7 +152,8 @@ discard block |
||
| 141 | 152 | * |
| 142 | 153 | * @param $value A class for alternate table rows. |
| 143 | 154 | */ |
| 144 | - public function setRowAlternateClass($value) { |
|
| 155 | + public function setRowAlternateClass($value) |
|
| 156 | + { |
|
| 145 | 157 | $this->rowAlternateClass= $value; |
| 146 | 158 | } |
| 147 | 159 | |
@@ -150,7 +162,8 @@ discard block |
||
| 150 | 162 | * |
| 151 | 163 | * @param $value Indicates the INPUT form element type attribute. |
| 152 | 164 | */ |
| 153 | - public function setFormElementType($value) { |
|
| 165 | + public function setFormElementType($value) |
|
| 166 | + { |
|
| 154 | 167 | $this->formElementType= $value; |
| 155 | 168 | } |
| 156 | 169 | |
@@ -159,7 +172,8 @@ discard block |
||
| 159 | 172 | * |
| 160 | 173 | * @param $value Indicates the INPUT form element name attribute. |
| 161 | 174 | */ |
| 162 | - public function setFormElementName($value) { |
|
| 175 | + public function setFormElementName($value) |
|
| 176 | + { |
|
| 163 | 177 | $this->formElementName= $value; |
| 164 | 178 | } |
| 165 | 179 | |
@@ -169,7 +183,8 @@ discard block |
||
| 169 | 183 | * |
| 170 | 184 | * @param $value Indicates the FORM name attribute. |
| 171 | 185 | */ |
| 172 | - public function setFormName($value) { |
|
| 186 | + public function setFormName($value) |
|
| 187 | + { |
|
| 173 | 188 | $this->formName= $value; |
| 174 | 189 | } |
| 175 | 190 | |
@@ -178,7 +193,8 @@ discard block |
||
| 178 | 193 | * |
| 179 | 194 | * @param $value Indicates the FORM action attribute. |
| 180 | 195 | */ |
| 181 | - public function setFormAction($value) { |
|
| 196 | + public function setFormAction($value) |
|
| 197 | + { |
|
| 182 | 198 | $this->formAction= $value; |
| 183 | 199 | } |
| 184 | 200 | |
@@ -187,7 +203,8 @@ discard block |
||
| 187 | 203 | * |
| 188 | 204 | * @param $value An Array of field keys to exclude from the table. |
| 189 | 205 | */ |
| 190 | - public function setExcludeFields($value) { |
|
| 206 | + public function setExcludeFields($value) |
|
| 207 | + { |
|
| 191 | 208 | $this->excludeFields= $value; |
| 192 | 209 | } |
| 193 | 210 | |
@@ -196,7 +213,8 @@ discard block |
||
| 196 | 213 | * |
| 197 | 214 | * @param $value 'ODD' or 'EVEN' to indicate the alternate row scheme. |
| 198 | 215 | */ |
| 199 | - public function setRowAlternatingScheme($value) { |
|
| 216 | + public function setRowAlternatingScheme($value) |
|
| 217 | + { |
|
| 200 | 218 | $this->rowAlternatingScheme= $value; |
| 201 | 219 | } |
| 202 | 220 | |
@@ -206,7 +224,8 @@ discard block |
||
| 206 | 224 | * |
| 207 | 225 | * @param $value The key of the field to add as a query string parameter. |
| 208 | 226 | */ |
| 209 | - public function setActionFieldName($value) { |
|
| 227 | + public function setActionFieldName($value) |
|
| 228 | + { |
|
| 210 | 229 | $this->actionField= $value; |
| 211 | 230 | } |
| 212 | 231 | |
@@ -216,7 +235,8 @@ discard block |
||
| 216 | 235 | * @param $value An Array of column widths in the order of the keys in the |
| 217 | 236 | * source table array. |
| 218 | 237 | */ |
| 219 | - public function setColumnWidths($widthArray) { |
|
| 238 | + public function setColumnWidths($widthArray) |
|
| 239 | + { |
|
| 220 | 240 | $this->columnWidths= $widthArray; |
| 221 | 241 | } |
| 222 | 242 | |
@@ -225,7 +245,8 @@ discard block |
||
| 225 | 245 | * |
| 226 | 246 | * @param $value Indicates the INPUT form element type attribute. |
| 227 | 247 | */ |
| 228 | - public function setSelectedValues($valueArray) { |
|
| 248 | + public function setSelectedValues($valueArray) |
|
| 249 | + { |
|
| 229 | 250 | $this->selectedValues= $valueArray; |
| 230 | 251 | } |
| 231 | 252 | |
@@ -235,7 +256,8 @@ discard block |
||
| 235 | 256 | * |
| 236 | 257 | * @param $value A string of additional content. |
| 237 | 258 | */ |
| 238 | - public function setExtra($value) { |
|
| 259 | + public function setExtra($value) |
|
| 260 | + { |
|
| 239 | 261 | $this->extra= $value; |
| 240 | 262 | } |
| 241 | 263 | |
@@ -244,7 +266,8 @@ discard block |
||
| 244 | 266 | * |
| 245 | 267 | * @param $columnPosition The index of the column to get the width for. |
| 246 | 268 | */ |
| 247 | - public function getColumnWidth($columnPosition) { |
|
| 269 | + public function getColumnWidth($columnPosition) |
|
| 270 | + { |
|
| 248 | 271 | $currentWidth= ''; |
| 249 | 272 | if (is_array($this->columnWidths)) { |
| 250 | 273 | $currentWidth= $this->columnWidths[$columnPosition] ? ' width="'.$this->columnWidths[$columnPosition].'" ' : ''; |
@@ -257,7 +280,8 @@ discard block |
||
| 257 | 280 | * |
| 258 | 281 | * @param $value The position of the current row being rendered. |
| 259 | 282 | */ |
| 260 | - public function determineRowClass($position) { |
|
| 283 | + public function determineRowClass($position) |
|
| 284 | + { |
|
| 261 | 285 | switch ($this->rowAlternatingScheme) { |
| 262 | 286 | case 'ODD' : |
| 263 | 287 | $modRemainder= 1; |
@@ -280,7 +304,8 @@ discard block |
||
| 280 | 304 | * |
| 281 | 305 | * @param $value Indicates the INPUT form element type attribute. |
| 282 | 306 | */ |
| 283 | - public function getCellAction($currentActionFieldValue) { |
|
| 307 | + public function getCellAction($currentActionFieldValue) |
|
| 308 | + { |
|
| 284 | 309 | if ($this->cellAction) { |
| 285 | 310 | $cellAction= ' onClick="javascript:window.location=\''.$this->cellAction.$this->actionField.'='.urlencode($currentActionFieldValue).'\'" '; |
| 286 | 311 | } |
@@ -293,7 +318,8 @@ discard block |
||
| 293 | 318 | * @param $currentActionFieldValue The value to be applied to the link action. |
| 294 | 319 | * @param $value The value of the cell. |
| 295 | 320 | */ |
| 296 | - public function createCellText($currentActionFieldValue, $value) { |
|
| 321 | + public function createCellText($currentActionFieldValue, $value) |
|
| 322 | + { |
|
| 297 | 323 | $cell .= $value; |
| 298 | 324 | if ($this->linkAction) { |
| 299 | 325 | $cell= '<a href="'.$this->linkAction.$this->actionField.'='.urlencode($currentActionFieldValue).'">'.$cell.'</a>'; |
@@ -305,7 +331,8 @@ discard block |
||
| 305 | 331 | * Sets an option to generate a check all link when checkbox is indicated |
| 306 | 332 | * as the table formElementType. |
| 307 | 333 | */ |
| 308 | - public function setAllOption() { |
|
| 334 | + public function setAllOption() |
|
| 335 | + { |
|
| 309 | 336 | $this->allOption= 1; |
| 310 | 337 | } |
| 311 | 338 | |
@@ -314,7 +341,8 @@ discard block |
||
| 314 | 341 | * |
| 315 | 342 | * @param $value Indicates the INPUT form element type attribute. |
| 316 | 343 | */ |
| 317 | - public function prepareLink($link) { |
|
| 344 | + public function prepareLink($link) |
|
| 345 | + { |
|
| 318 | 346 | if (strstr($link, '?')) { |
| 319 | 347 | $end= '&'; |
| 320 | 348 | } else { |
@@ -333,7 +361,8 @@ discard block |
||
| 333 | 361 | * the $fieldsArray where the values represent the alt heading content |
| 334 | 362 | * for each column. |
| 335 | 363 | */ |
| 336 | - public function create($fieldsArray, $fieldHeadersArray=array(),$linkpage="") { |
|
| 364 | + public function create($fieldsArray, $fieldHeadersArray=array(),$linkpage="") |
|
| 365 | + { |
|
| 337 | 366 | global $_lang; |
| 338 | 367 | if (is_array($fieldsArray)) { |
| 339 | 368 | $i= 0; |
@@ -369,7 +398,8 @@ discard block |
||
| 369 | 398 | if ($this->formElementType) { |
| 370 | 399 | $table= "\n".'<form id="'.$this->formName.'" name="'.$this->formName.'" action="'.$this->formAction.'" method="POST">'.$table; |
| 371 | 400 | } |
| 372 | - if (strlen($this->pageNav) > 1) {//changed to display the pagination if exists. |
|
| 401 | + if (strlen($this->pageNav) > 1) { |
|
| 402 | +//changed to display the pagination if exists. |
|
| 373 | 403 | /* commented this part because of cookie |
| 374 | 404 | $table .= '<div id="max-display-records" ><select style="display:inline" onchange="javascript:updatePageSize(this[this.selectedIndex].value);">'; |
| 375 | 405 | $pageSizes= array (10, 25, 50, 100, 250); |
@@ -416,7 +446,8 @@ discard block |
||
| 416 | 446 | * @param $numRecords The number of records to show per page. |
| 417 | 447 | * @param $qs An optional query string to be appended to the paging links |
| 418 | 448 | */ |
| 419 | - public function createPagingNavigation($numRecords, $qs='') { |
|
| 449 | + public function createPagingNavigation($numRecords, $qs='') |
|
| 450 | + { |
|
| 420 | 451 | global $_lang; |
| 421 | 452 | $currentPage= (is_numeric($_GET['page']) ? $_GET['page'] : 1); |
| 422 | 453 | $numPages= ceil($numRecords / MAX_DISPLAY_RECORDS_NUM); |
@@ -431,10 +462,11 @@ discard block |
||
| 431 | 462 | $offset= -4 + ($currentPage < 5 ? (5 - $currentPage) : 0); |
| 432 | 463 | $i= 1; |
| 433 | 464 | 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); |
|
| 465 | + if ($currentPage == $currentPage + $offset) { |
|
| 466 | + $nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset, true); |
|
| 467 | + } else { |
|
| 468 | + $nav .= $this->createPageLink($currentURL, $currentPage + $offset, $currentPage + $offset); |
|
| 469 | + } |
|
| 438 | 470 | $i ++; |
| 439 | 471 | $offset ++; |
| 440 | 472 | } |
@@ -457,11 +489,14 @@ discard block |
||
| 457 | 489 | * @param $currentPage Indicates if the link is to the current page. |
| 458 | 490 | * @param $qs And optional query string to be appended to the link. |
| 459 | 491 | */ |
| 460 | - public function createPageLink($link='', $pageNum, $displayText, $currentPage=false, $qs='') { |
|
| 492 | + public function createPageLink($link='', $pageNum, $displayText, $currentPage=false, $qs='') |
|
| 493 | + { |
|
| 461 | 494 | global $modx; |
| 462 | 495 | $orderBy= !empty($_GET['orderby'])? '&orderby=' . $_GET['orderby']: ''; |
| 463 | 496 | $orderDir= !empty($_GET['orderdir'])? '&orderdir=' . $_GET['orderdir']: ''; |
| 464 | - if (!empty($qs)) $qs= "?$qs"; |
|
| 497 | + if (!empty($qs)) { |
|
| 498 | + $qs= "?$qs"; |
|
| 499 | + } |
|
| 465 | 500 | $link= empty($link)? $modx->makeUrl($modx->documentIdentifier, $modx->documentObject['alias'], $qs . "page=$pageNum$orderBy$orderDir"): $this->prepareLink($link) . "page=$pageNum"; |
| 466 | 501 | $nav .= '<li'.($currentPage? ' class="currentPage"': '').'><a'.($currentPage? ' class="currentPage"': '').' href="'.$link.'">'.$displayText.'</a></li>'."\n"; |
| 467 | 502 | return $nav; |
@@ -474,7 +509,8 @@ discard block |
||
| 474 | 509 | * @param $isChecked Indicates if the checked attribute should apply to the |
| 475 | 510 | * element. |
| 476 | 511 | */ |
| 477 | - public function addFormField($value, $isChecked) { |
|
| 512 | + public function addFormField($value, $isChecked) |
|
| 513 | + { |
|
| 478 | 514 | if ($this->formElementType) { |
| 479 | 515 | $checked= $isChecked? "checked ": ""; |
| 480 | 516 | $field= "\t\t".'<td><input type="'.$this->formElementType.'" name="'. ($this->formElementName ? $this->formElementName : $value).'" value="'.$value.'" '.$checked.'/></td>'."\n"; |
@@ -486,7 +522,8 @@ discard block |
||
| 486 | 522 | * Generates the proper LIMIT clause for queries to retrieve paged results in |
| 487 | 523 | * a MakeTable $fieldsArray. |
| 488 | 524 | */ |
| 489 | - public function handlePaging() { |
|
| 525 | + public function handlePaging() |
|
| 526 | + { |
|
| 490 | 527 | $offset= (is_numeric($_GET['page']) && $_GET['page'] > 0) ? $_GET['page'] - 1 : 0; |
| 491 | 528 | $limitClause= ' LIMIT '. ($offset * MAX_DISPLAY_RECORDS_NUM).', '.MAX_DISPLAY_RECORDS_NUM; |
| 492 | 529 | return $limitClause; |
@@ -498,7 +535,8 @@ discard block |
||
| 498 | 535 | * |
| 499 | 536 | * @param $natural_order If true, the results are returned in natural order. |
| 500 | 537 | */ |
| 501 | - public function handleSorting($natural_order=false) { |
|
| 538 | + public function handleSorting($natural_order=false) |
|
| 539 | + { |
|
| 502 | 540 | $orderByClause= ''; |
| 503 | 541 | if (!$natural_order) { |
| 504 | 542 | $orderby= !empty($_GET['orderby'])? $_GET['orderby']: "id"; |
@@ -516,7 +554,8 @@ discard block |
||
| 516 | 554 | * @param $text The text for the link (e.g. table column header). |
| 517 | 555 | * @param $qs An optional query string to append to the order by link. |
| 518 | 556 | */ |
| 519 | - public function prepareOrderByLink($key, $text, $qs='') { |
|
| 557 | + public function prepareOrderByLink($key, $text, $qs='') |
|
| 558 | + { |
|
| 520 | 559 | global $modx; |
| 521 | 560 | if (!empty($_GET['orderdir'])) { |
| 522 | 561 | $orderDir= strtolower($_GET['orderdir'])=='desc'? '&orderdir=asc': '&orderdir=desc'; |
@@ -524,7 +563,9 @@ discard block |
||
| 524 | 563 | $orderDir= '&orderdir=asc'; |
| 525 | 564 | } |
| 526 | 565 | if (!empty($qs)) { |
| 527 | - if (!strrpos($qs, '&')==strlen($qs)-1) $qs.= '&'; |
|
| 566 | + if (!strrpos($qs, '&')==strlen($qs)-1) { |
|
| 567 | + $qs.= '&'; |
|
| 568 | + } |
|
| 528 | 569 | } |
| 529 | 570 | return '<a href="[~'.$modx->documentIdentifier.'~]?'.$qs.'orderby='.$key.$orderDir.'">'.$text.'</a>'; |
| 530 | 571 | } |
@@ -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 | } |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if(!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', MODX_MANAGER_PATH.'includes/'); |
|
| 3 | +if (!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', MODX_MANAGER_PATH.'includes/'); |
|
| 4 | 4 | |
| 5 | -class MODIFIERS { |
|
| 5 | +class MODIFIERS{ |
|
| 6 | 6 | |
| 7 | 7 | public $placeholders = array(); |
| 8 | 8 | public $vars = array(); |
@@ -30,14 +30,14 @@ 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 | - public function phxFilter($key,$value,$modifiers) |
|
| 33 | + public function phxFilter($key, $value, $modifiers) |
|
| 34 | 34 | { |
| 35 | 35 | global $modx; |
| 36 | - if(substr($modifiers,0,3)!=='id(') $value = $this->parseDocumentSource($value); |
|
| 36 | + if (substr($modifiers, 0, 3) !== 'id(') $value = $this->parseDocumentSource($value); |
|
| 37 | 37 | $this->srcValue = $value; |
| 38 | 38 | $modifiers = trim($modifiers); |
| 39 | - $modifiers = ':'.trim($modifiers,':'); |
|
| 40 | - $modifiers = str_replace(array("\r\n","\r"), "\n", $modifiers); |
|
| 39 | + $modifiers = ':'.trim($modifiers, ':'); |
|
| 40 | + $modifiers = str_replace(array("\r\n", "\r"), "\n", $modifiers); |
|
| 41 | 41 | $modifiers = $this->splitEachModifiers($modifiers); |
| 42 | 42 | |
| 43 | 43 | $this->placeholders = array(); |
@@ -45,118 +45,118 @@ discard block |
||
| 45 | 45 | $this->placeholders['dummy'] = ''; |
| 46 | 46 | $this->condition = array(); |
| 47 | 47 | $this->vars = array(); |
| 48 | - $this->vars['name'] = & $key; |
|
| 49 | - $value = $this->parsePhx($key,$value,$modifiers); |
|
| 48 | + $this->vars['name'] = & $key; |
|
| 49 | + $value = $this->parsePhx($key, $value, $modifiers); |
|
| 50 | 50 | $this->vars = array(); |
| 51 | 51 | return $value; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public function _getDelim($mode,$modifiers) { |
|
| 55 | - $c = substr($modifiers,0,1); |
|
| 56 | - if(!in_array($c, array('"', "'", '`')) ) return false; |
|
| 54 | + public function _getDelim($mode, $modifiers){ |
|
| 55 | + $c = substr($modifiers, 0, 1); |
|
| 56 | + if (!in_array($c, array('"', "'", '`'))) return false; |
|
| 57 | 57 | |
| 58 | - $modifiers = substr($modifiers,1); |
|
| 59 | - $closure = $mode=='(' ? "{$c})" : $c; |
|
| 60 | - if(strpos($modifiers, $closure)===false) return false; |
|
| 58 | + $modifiers = substr($modifiers, 1); |
|
| 59 | + $closure = $mode == '(' ? "{$c})" : $c; |
|
| 60 | + if (strpos($modifiers, $closure) === false) return false; |
|
| 61 | 61 | |
| 62 | 62 | return $c; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - public function _getOpt($mode,$delim,$modifiers) { |
|
| 66 | - if($delim) { |
|
| 67 | - if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1); |
|
| 65 | + public function _getOpt($mode, $delim, $modifiers){ |
|
| 66 | + if ($delim) { |
|
| 67 | + if ($mode == '(') return substr($modifiers, 1, strpos($modifiers, $delim.')') - 1); |
|
| 68 | 68 | |
| 69 | - return substr($modifiers,1,strpos($modifiers,$delim,1)-1); |
|
| 69 | + return substr($modifiers, 1, strpos($modifiers, $delim, 1) - 1); |
|
| 70 | 70 | } |
| 71 | 71 | else { |
| 72 | - if($mode=='(') return substr($modifiers,0,strpos($modifiers, ')') ); |
|
| 72 | + if ($mode == '(') return substr($modifiers, 0, strpos($modifiers, ')')); |
|
| 73 | 73 | |
| 74 | 74 | $chars = str_split($modifiers); |
| 75 | - $opt=''; |
|
| 76 | - foreach($chars as $c) { |
|
| 77 | - if($c==':' || $c==')') break; |
|
| 78 | - $opt .=$c; |
|
| 75 | + $opt = ''; |
|
| 76 | + foreach ($chars as $c) { |
|
| 77 | + if ($c == ':' || $c == ')') break; |
|
| 78 | + $opt .= $c; |
|
| 79 | 79 | } |
| 80 | 80 | return $opt; |
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | - public function _getRemainModifiers($mode,$delim,$modifiers) { |
|
| 84 | - if($delim) { |
|
| 85 | - if($mode=='(') |
|
| 86 | - return $this->_fetchContent($modifiers, $delim . ')'); |
|
| 83 | + public function _getRemainModifiers($mode, $delim, $modifiers){ |
|
| 84 | + if ($delim) { |
|
| 85 | + if ($mode == '(') |
|
| 86 | + return $this->_fetchContent($modifiers, $delim.')'); |
|
| 87 | 87 | else { |
| 88 | 88 | $modifiers = trim($modifiers); |
| 89 | - $modifiers = substr($modifiers,1); |
|
| 89 | + $modifiers = substr($modifiers, 1); |
|
| 90 | 90 | return $this->_fetchContent($modifiers, $delim); |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | else { |
| 94 | - if($mode=='(') return $this->_fetchContent($modifiers, ')'); |
|
| 94 | + if ($mode == '(') return $this->_fetchContent($modifiers, ')'); |
|
| 95 | 95 | $chars = str_split($modifiers); |
| 96 | - foreach($chars as $c) { |
|
| 97 | - if($c==':') return $modifiers; |
|
| 98 | - else $modifiers = substr($modifiers,1); |
|
| 96 | + foreach ($chars as $c) { |
|
| 97 | + if ($c == ':') return $modifiers; |
|
| 98 | + else $modifiers = substr($modifiers, 1); |
|
| 99 | 99 | } |
| 100 | 100 | return $modifiers; |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - public function _fetchContent($string,$delim) { |
|
| 104 | + public function _fetchContent($string, $delim){ |
|
| 105 | 105 | $len = strlen($delim); |
| 106 | 106 | $string = $this->parseDocumentSource($string); |
| 107 | - return substr($string,strpos($string, $delim)+$len); |
|
| 107 | + return substr($string, strpos($string, $delim) + $len); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - public function splitEachModifiers($modifiers) { |
|
| 110 | + public function splitEachModifiers($modifiers){ |
|
| 111 | 111 | global $modx; |
| 112 | 112 | |
| 113 | 113 | $cmd = ''; |
| 114 | 114 | $bt = ''; |
| 115 | 115 | $result = array(); |
| 116 | - while($bt!==$modifiers) { |
|
| 116 | + while ($bt !== $modifiers) { |
|
| 117 | 117 | $bt = $modifiers; |
| 118 | - $c = substr($modifiers,0,1); |
|
| 119 | - $modifiers = substr($modifiers,1); |
|
| 118 | + $c = substr($modifiers, 0, 1); |
|
| 119 | + $modifiers = substr($modifiers, 1); |
|
| 120 | 120 | |
| 121 | - if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>= |
|
| 122 | - $c = substr($modifiers,strlen($match[1]),1); |
|
| 121 | + if ($c === ':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>= |
|
| 122 | + $c = substr($modifiers, strlen($match[1]), 1); |
|
| 123 | 123 | $debuginfo = "#i=0 #c=[{$c}] #m=[{$modifiers}]"; |
| 124 | - if($c==='(') $modifiers = substr($modifiers,strlen($match[1])+1); |
|
| 125 | - else $modifiers = substr($modifiers,strlen($match[1])); |
|
| 124 | + if ($c === '(') $modifiers = substr($modifiers, strlen($match[1]) + 1); |
|
| 125 | + else $modifiers = substr($modifiers, strlen($match[1])); |
|
| 126 | 126 | |
| 127 | - $delim = $this->_getDelim($c,$modifiers); |
|
| 128 | - $opt = $this->_getOpt($c,$delim,$modifiers); |
|
| 129 | - $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers)); |
|
| 127 | + $delim = $this->_getDelim($c, $modifiers); |
|
| 128 | + $opt = $this->_getOpt($c, $delim, $modifiers); |
|
| 129 | + $modifiers = trim($this->_getRemainModifiers($c, $delim, $modifiers)); |
|
| 130 | 130 | |
| 131 | - $result[]=array('cmd'=>trim($match[1]),'opt'=>$opt,'debuginfo'=>$debuginfo); |
|
| 131 | + $result[] = array('cmd'=>trim($match[1]), 'opt'=>$opt, 'debuginfo'=>$debuginfo); |
|
| 132 | 132 | $cmd = ''; |
| 133 | 133 | } |
| 134 | - elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ... |
|
| 135 | - $modifiers = substr($modifiers,strlen($match[0])); |
|
| 136 | - $result[]=array('cmd'=>'math','opt'=>'%s'.$c.$match[0]); |
|
| 134 | + elseif (in_array($c, array('+', '-', '*', '/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ... |
|
| 135 | + $modifiers = substr($modifiers, strlen($match[0])); |
|
| 136 | + $result[] = array('cmd'=>'math', 'opt'=>'%s'.$c.$match[0]); |
|
| 137 | 137 | $cmd = ''; |
| 138 | 138 | } |
| 139 | - elseif($c==='(' || $c==='=') { |
|
| 139 | + elseif ($c === '(' || $c === '=') { |
|
| 140 | 140 | $modifiers = $m1 = trim($modifiers); |
| 141 | - $delim = $this->_getDelim($c,$modifiers); |
|
| 142 | - $opt = $this->_getOpt($c,$delim,$modifiers); |
|
| 143 | - $modifiers = trim($this->_getRemainModifiers($c,$delim,$modifiers)); |
|
| 141 | + $delim = $this->_getDelim($c, $modifiers); |
|
| 142 | + $opt = $this->_getOpt($c, $delim, $modifiers); |
|
| 143 | + $modifiers = trim($this->_getRemainModifiers($c, $delim, $modifiers)); |
|
| 144 | 144 | $debuginfo = "#i=1 #c=[{$c}] #delim=[{$delim}] #m1=[{$m1}] remainMdf=[{$modifiers}]"; |
| 145 | 145 | |
| 146 | - $result[]=array('cmd'=>trim($cmd),'opt'=>$opt,'debuginfo'=>$debuginfo); |
|
| 146 | + $result[] = array('cmd'=>trim($cmd), 'opt'=>$opt, 'debuginfo'=>$debuginfo); |
|
| 147 | 147 | |
| 148 | 148 | $cmd = ''; |
| 149 | 149 | } |
| 150 | - elseif($c==':') { |
|
| 150 | + elseif ($c == ':') { |
|
| 151 | 151 | $debuginfo = "#i=2 #c=[{$c}] #m=[{$modifiers}]"; |
| 152 | - if($cmd!=='') $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
|
| 152 | + if ($cmd !== '') $result[] = array('cmd'=>trim($cmd), 'opt'=>'', 'debuginfo'=>$debuginfo); |
|
| 153 | 153 | |
| 154 | 154 | $cmd = ''; |
| 155 | 155 | } |
| 156 | - elseif(trim($modifiers)=='' && trim($cmd)!=='') { |
|
| 156 | + elseif (trim($modifiers) == '' && trim($cmd) !== '') { |
|
| 157 | 157 | $debuginfo = "#i=3 #c=[{$c}] #m=[{$modifiers}]"; |
| 158 | 158 | $cmd .= $c; |
| 159 | - $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
|
| 159 | + $result[] = array('cmd'=>trim($cmd), 'opt'=>'', 'debuginfo'=>$debuginfo); |
|
| 160 | 160 | |
| 161 | 161 | break; |
| 162 | 162 | } |
@@ -165,65 +165,65 @@ discard block |
||
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if(empty($result)) return array(); |
|
| 168 | + if (empty($result)) return array(); |
|
| 169 | 169 | |
| 170 | - foreach($result as $i=>$a) |
|
| 170 | + foreach ($result as $i=>$a) |
|
| 171 | 171 | { |
| 172 | 172 | $a['opt'] = $this->parseDocumentSource($a['opt']); |
| 173 | - $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'],$this->placeholders); |
|
| 173 | + $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'], $this->placeholders); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | return $result; |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - public function parsePhx($key,$value,$modifiers) |
|
| 179 | + public function parsePhx($key, $value, $modifiers) |
|
| 180 | 180 | { |
| 181 | 181 | global $modx; |
| 182 | 182 | $lastKey = ''; |
| 183 | - $cacheKey = md5(sprintf('parsePhx#%s#%s#%s',$key,$value,print_r($modifiers,true))); |
|
| 184 | - if(isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey]; |
|
| 185 | - if(empty($modifiers)) return ''; |
|
| 183 | + $cacheKey = md5(sprintf('parsePhx#%s#%s#%s', $key, $value, print_r($modifiers, true))); |
|
| 184 | + if (isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey]; |
|
| 185 | + if (empty($modifiers)) return ''; |
|
| 186 | 186 | |
| 187 | - foreach($modifiers as $m) |
|
| 187 | + foreach ($modifiers as $m) |
|
| 188 | 188 | { |
| 189 | 189 | $lastKey = strtolower($m['cmd']); |
| 190 | 190 | } |
| 191 | - $_ = explode(',',$this->condModifiers); |
|
| 192 | - if(in_array($lastKey,$_)) |
|
| 191 | + $_ = explode(',', $this->condModifiers); |
|
| 192 | + if (in_array($lastKey, $_)) |
|
| 193 | 193 | { |
| 194 | - $modifiers[] = array('cmd'=>'then','opt'=>'1'); |
|
| 195 | - $modifiers[] = array('cmd'=>'else','opt'=>'0'); |
|
| 194 | + $modifiers[] = array('cmd'=>'then', 'opt'=>'1'); |
|
| 195 | + $modifiers[] = array('cmd'=>'else', 'opt'=>'0'); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - foreach($modifiers as $i=>$a) |
|
| 198 | + foreach ($modifiers as $i=>$a) |
|
| 199 | 199 | { |
| 200 | - $value = $this->Filter($key,$value, $a['cmd'], $a['opt']); |
|
| 200 | + $value = $this->Filter($key, $value, $a['cmd'], $a['opt']); |
|
| 201 | 201 | } |
| 202 | 202 | $this->tmpCache[$cacheKey] = $value; |
| 203 | 203 | return $value; |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | // Parser: modifier detection and eXtended processing if needed |
| 207 | - public function Filter($key, $value, $cmd, $opt='') |
|
| 207 | + public function Filter($key, $value, $cmd, $opt = '') |
|
| 208 | 208 | { |
| 209 | 209 | global $modx; |
| 210 | 210 | |
| 211 | - if($key==='documentObject') $value = $modx->documentIdentifier; |
|
| 211 | + if ($key === 'documentObject') $value = $modx->documentIdentifier; |
|
| 212 | 212 | $cmd = $this->parseDocumentSource($cmd); |
| 213 | - if(preg_match('@^[1-9][/0-9]*$@',$cmd)) |
|
| 213 | + if (preg_match('@^[1-9][/0-9]*$@', $cmd)) |
|
| 214 | 214 | { |
| 215 | - if(strpos($cmd,'/')!==false) |
|
| 216 | - $cmd = $this->substr($cmd,strrpos($cmd,'/')+1); |
|
| 215 | + if (strpos($cmd, '/') !== false) |
|
| 216 | + $cmd = $this->substr($cmd, strrpos($cmd, '/') + 1); |
|
| 217 | 217 | $opt = $cmd; |
| 218 | 218 | $cmd = 'id'; |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - if(isset($modx->snippetCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
| 222 | - elseif(isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
| 221 | + if (isset($modx->snippetCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
| 222 | + elseif (isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
| 223 | 223 | else $this->elmName = ''; |
| 224 | 224 | |
| 225 | 225 | $cmd = strtolower($cmd); |
| 226 | - if($this->elmName!=='') |
|
| 226 | + if ($this->elmName !== '') |
|
| 227 | 227 | $value = $this->getValueFromElement($key, $value, $cmd, $opt); |
| 228 | 228 | else |
| 229 | 229 | $value = $this->getValueFromPreset($key, $value, $cmd, $opt); |
@@ -233,12 +233,12 @@ discard block |
||
| 233 | 233 | return $value; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - public function isEmpty($cmd,$value) |
|
| 236 | + public function isEmpty($cmd, $value) |
|
| 237 | 237 | { |
| 238 | - if($value!=='') return false; |
|
| 238 | + if ($value !== '') return false; |
|
| 239 | 239 | |
| 240 | - $_ = explode(',', $this->condModifiers . ',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary'); |
|
| 241 | - if(in_array($cmd,$_)) return false; |
|
| 240 | + $_ = explode(',', $this->condModifiers.',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary'); |
|
| 241 | + if (in_array($cmd, $_)) return false; |
|
| 242 | 242 | else return true; |
| 243 | 243 | } |
| 244 | 244 | |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | { |
| 247 | 247 | global $modx; |
| 248 | 248 | |
| 249 | - if($this->isEmpty($cmd,$value)) return ''; |
|
| 249 | + if ($this->isEmpty($cmd, $value)) return ''; |
|
| 250 | 250 | |
| 251 | 251 | $this->key = $key; |
| 252 | 252 | $this->value = $value; |
@@ -257,83 +257,83 @@ discard block |
||
| 257 | 257 | ##### Conditional Modifiers |
| 258 | 258 | case 'input': |
| 259 | 259 | case 'if': |
| 260 | - if(!$opt) return $value; |
|
| 260 | + if (!$opt) return $value; |
|
| 261 | 261 | return $opt; |
| 262 | 262 | case '=': |
| 263 | 263 | case 'eq': |
| 264 | 264 | case 'is': |
| 265 | 265 | case 'equals': |
| 266 | - $this->condition[] = (int)($value == $opt); break; |
|
| 266 | + $this->condition[] = (int) ($value == $opt); break; |
|
| 267 | 267 | case 'neq': |
| 268 | 268 | case 'ne': |
| 269 | 269 | case 'notequals': |
| 270 | 270 | case 'isnot': |
| 271 | 271 | case 'isnt': |
| 272 | 272 | case 'not': |
| 273 | - $this->condition[] = (int)($value != $opt);break; |
|
| 273 | + $this->condition[] = (int) ($value != $opt); break; |
|
| 274 | 274 | case '%': |
| 275 | - $this->condition[] = (int)($value%$opt==0);break; |
|
| 275 | + $this->condition[] = (int) ($value % $opt == 0); break; |
|
| 276 | 276 | case 'isempty': |
| 277 | - $this->condition[] = (int)(empty($value)); break; |
|
| 277 | + $this->condition[] = (int) (empty($value)); break; |
|
| 278 | 278 | case 'isntempty': |
| 279 | 279 | case 'isnotempty': |
| 280 | - $this->condition[] = (int)(!empty($value)); break; |
|
| 280 | + $this->condition[] = (int) (!empty($value)); break; |
|
| 281 | 281 | case '>=': |
| 282 | 282 | case 'gte': |
| 283 | 283 | case 'eg': |
| 284 | 284 | case 'isgte': |
| 285 | - $this->condition[] = (int)($value >= $opt);break; |
|
| 285 | + $this->condition[] = (int) ($value >= $opt); break; |
|
| 286 | 286 | case '<=': |
| 287 | 287 | case 'lte': |
| 288 | 288 | case 'el': |
| 289 | 289 | case 'islte': |
| 290 | - $this->condition[] = (int)($value <= $opt);break; |
|
| 290 | + $this->condition[] = (int) ($value <= $opt); break; |
|
| 291 | 291 | case '>': |
| 292 | 292 | case 'gt': |
| 293 | 293 | case 'greaterthan': |
| 294 | 294 | case 'isgreaterthan': |
| 295 | 295 | case 'isgt': |
| 296 | - $this->condition[] = (int)($value > $opt);break; |
|
| 296 | + $this->condition[] = (int) ($value > $opt); break; |
|
| 297 | 297 | case '<': |
| 298 | 298 | case 'lt': |
| 299 | 299 | case 'lowerthan': |
| 300 | 300 | case 'islowerthan': |
| 301 | 301 | case 'islt': |
| 302 | - $this->condition[] = (int)($value < $opt);break; |
|
| 302 | + $this->condition[] = (int) ($value < $opt); break; |
|
| 303 | 303 | case 'find': |
| 304 | - $this->condition[] = (int)(strpos($value, $opt)!==false);break; |
|
| 304 | + $this->condition[] = (int) (strpos($value, $opt) !== false); break; |
|
| 305 | 305 | case 'inarray': |
| 306 | 306 | case 'in_array': |
| 307 | 307 | case 'in': |
| 308 | 308 | $opt = explode(',', $opt); |
| 309 | - $this->condition[] = (int)(in_array($value, $opt)!==false);break; |
|
| 309 | + $this->condition[] = (int) (in_array($value, $opt) !== false); break; |
|
| 310 | 310 | case 'wildcard_match': |
| 311 | 311 | case 'wcard_match': |
| 312 | 312 | case 'wildcard': |
| 313 | 313 | case 'wcard': |
| 314 | 314 | case 'fnmatch': |
| 315 | - $this->condition[] = (int)(fnmatch($opt, $value)!==false);break; |
|
| 315 | + $this->condition[] = (int) (fnmatch($opt, $value) !== false); break; |
|
| 316 | 316 | case 'is_file': |
| 317 | 317 | case 'is_dir': |
| 318 | 318 | case 'file_exists': |
| 319 | 319 | case 'is_readable': |
| 320 | 320 | case 'is_writable': |
| 321 | - if(!$opt) $path = $value; |
|
| 321 | + if (!$opt) $path = $value; |
|
| 322 | 322 | else $path = $opt; |
| 323 | - if(strpos($path,MODX_MANAGER_PATH)!==false) exit('Can not read core path'); |
|
| 324 | - if(strpos($path,$modx->config['base_path'])===false) $path = ltrim($path,'/'); |
|
| 325 | - $this->condition[] = (int)($cmd($path)!==false);break; |
|
| 323 | + if (strpos($path, MODX_MANAGER_PATH) !== false) exit('Can not read core path'); |
|
| 324 | + if (strpos($path, $modx->config['base_path']) === false) $path = ltrim($path, '/'); |
|
| 325 | + $this->condition[] = (int) ($cmd($path) !== false); break; |
|
| 326 | 326 | case 'is_image': |
| 327 | - if(!$opt) $path = $value; |
|
| 327 | + if (!$opt) $path = $value; |
|
| 328 | 328 | else $path = $opt; |
| 329 | - if(!is_file($path)) {$this->condition[]='0';break;} |
|
| 329 | + if (!is_file($path)) {$this->condition[] = '0'; break; } |
|
| 330 | 330 | $_ = getimagesize($path); |
| 331 | - $this->condition[] = (int)($_[0]);break; |
|
| 331 | + $this->condition[] = (int) ($_[0]); break; |
|
| 332 | 332 | case 'regex': |
| 333 | 333 | case 'preg': |
| 334 | 334 | case 'preg_match': |
| 335 | 335 | case 'isinrole': |
| 336 | - $this->condition[] = (int)(preg_match($opt,$value));break; |
|
| 336 | + $this->condition[] = (int) (preg_match($opt, $value)); break; |
|
| 337 | 337 | case 'ir': |
| 338 | 338 | case 'memberof': |
| 339 | 339 | case 'mo': |
@@ -341,50 +341,50 @@ discard block |
||
| 341 | 341 | $this->condition[] = $this->includeMdfFile('memberof'); |
| 342 | 342 | break; |
| 343 | 343 | case 'or': |
| 344 | - $this->condition[] = '||';break; |
|
| 344 | + $this->condition[] = '||'; break; |
|
| 345 | 345 | case 'and': |
| 346 | - $this->condition[] = '&&';break; |
|
| 346 | + $this->condition[] = '&&'; break; |
|
| 347 | 347 | case 'show': |
| 348 | 348 | case 'this': |
| 349 | - $conditional = join(' ',$this->condition); |
|
| 350 | - $isvalid = (int)(eval("return ({$conditional});")); |
|
| 349 | + $conditional = join(' ', $this->condition); |
|
| 350 | + $isvalid = (int) (eval("return ({$conditional});")); |
|
| 351 | 351 | if ($isvalid) return $this->srcValue; |
| 352 | 352 | return NULL; |
| 353 | 353 | case 'then': |
| 354 | - $conditional = join(' ',$this->condition); |
|
| 355 | - $isvalid = (int)eval("return ({$conditional});"); |
|
| 354 | + $conditional = join(' ', $this->condition); |
|
| 355 | + $isvalid = (int) eval("return ({$conditional});"); |
|
| 356 | 356 | if ($isvalid) return $opt; |
| 357 | 357 | return null; |
| 358 | 358 | case 'else': |
| 359 | - $conditional = join(' ',$this->condition); |
|
| 360 | - $isvalid = (int)eval("return ({$conditional});"); |
|
| 359 | + $conditional = join(' ', $this->condition); |
|
| 360 | + $isvalid = (int) eval("return ({$conditional});"); |
|
| 361 | 361 | if (!$isvalid) return $opt; |
| 362 | 362 | break; |
| 363 | 363 | case 'select': |
| 364 | 364 | case 'switch': |
| 365 | - $raw = explode('&',$opt); |
|
| 365 | + $raw = explode('&', $opt); |
|
| 366 | 366 | $map = array(); |
| 367 | 367 | $c = count($raw); |
| 368 | - for($m=0; $m<$c; $m++) { |
|
| 369 | - $mi = explode('=',$raw[$m],2); |
|
| 368 | + for ($m = 0; $m < $c; $m++) { |
|
| 369 | + $mi = explode('=', $raw[$m], 2); |
|
| 370 | 370 | $map[$mi[0]] = $mi[1]; |
| 371 | 371 | } |
| 372 | - if(isset($map[$value])) return $map[$value]; |
|
| 372 | + if (isset($map[$value])) return $map[$value]; |
|
| 373 | 373 | else return ''; |
| 374 | 374 | ##### End of Conditional Modifiers |
| 375 | 375 | |
| 376 | 376 | ##### Encode / Decode / Hash / Escape |
| 377 | 377 | case 'htmlent': |
| 378 | 378 | case 'htmlentities': |
| 379 | - return htmlentities($value,ENT_QUOTES,$modx->config['modx_charset']); |
|
| 379 | + return htmlentities($value, ENT_QUOTES, $modx->config['modx_charset']); |
|
| 380 | 380 | case 'html_entity_decode': |
| 381 | 381 | case 'decode_html': |
| 382 | 382 | case 'html_decode': |
| 383 | - return html_entity_decode($value,ENT_QUOTES,$modx->config['modx_charset']); |
|
| 383 | + return html_entity_decode($value, ENT_QUOTES, $modx->config['modx_charset']); |
|
| 384 | 384 | case 'esc': |
| 385 | 385 | case 'escape': |
| 386 | 386 | $value = preg_replace('/&(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset'])); |
| 387 | - return str_replace(array('[', ']', '`'),array('[', ']', '`'),$value); |
|
| 387 | + return str_replace(array('[', ']', '`'), array('[', ']', '`'), $value); |
|
| 388 | 388 | case 'sql_escape': |
| 389 | 389 | case 'encode_js': |
| 390 | 390 | return $modx->db->escape($value); |
@@ -394,39 +394,39 @@ discard block |
||
| 394 | 394 | case 'html_encode': |
| 395 | 395 | return preg_replace('/&(#[0-9]+|[a-z]+);/i', '&$1;', htmlspecialchars($value, ENT_QUOTES, $modx->config['modx_charset'])); |
| 396 | 396 | case 'spam_protect': |
| 397 | - return str_replace(array('@','.'),array('@','.'),$value); |
|
| 397 | + return str_replace(array('@', '.'), array('@', '.'), $value); |
|
| 398 | 398 | case 'strip': |
| 399 | - if($opt==='') $opt = ' '; |
|
| 399 | + if ($opt === '') $opt = ' '; |
|
| 400 | 400 | return preg_replace('/[\n\r\t\s]+/', $opt, $value); |
| 401 | 401 | case 'strip_linefeeds': |
| 402 | - return str_replace(array("\n","\r"), '', $value); |
|
| 402 | + return str_replace(array("\n", "\r"), '', $value); |
|
| 403 | 403 | case 'notags': |
| 404 | 404 | case 'strip_tags': |
| 405 | 405 | case 'remove_html': |
| 406 | - if($opt!=='') |
|
| 406 | + if ($opt !== '') |
|
| 407 | 407 | { |
| 408 | 408 | $param = array(); |
| 409 | - foreach(explode(',',$opt) as $v) |
|
| 409 | + foreach (explode(',', $opt) as $v) |
|
| 410 | 410 | { |
| 411 | - $v = trim($v,'</> '); |
|
| 411 | + $v = trim($v, '</> '); |
|
| 412 | 412 | $param[] = "<{$v}>"; |
| 413 | 413 | } |
| 414 | - $params = join(',',$param); |
|
| 414 | + $params = join(',', $param); |
|
| 415 | 415 | } |
| 416 | 416 | else $params = ''; |
| 417 | - if(!strpos($params,'<br>')===false) { |
|
| 418 | - $value = preg_replace('@(<br[ /]*>)\n@','$1',$value); |
|
| 419 | - $value = preg_replace('@<br[ /]*>@',"\n",$value); |
|
| 417 | + if (!strpos($params, '<br>') === false) { |
|
| 418 | + $value = preg_replace('@(<br[ /]*>)\n@', '$1', $value); |
|
| 419 | + $value = preg_replace('@<br[ /]*>@', "\n", $value); |
|
| 420 | 420 | } |
| 421 | - return $this->strip_tags($value,$params); |
|
| 421 | + return $this->strip_tags($value, $params); |
|
| 422 | 422 | case 'urlencode': |
| 423 | 423 | case 'url_encode': |
| 424 | 424 | case 'encode_url': |
| 425 | 425 | return urlencode($value); |
| 426 | 426 | case 'base64_decode': |
| 427 | - if($opt!=='false') $opt = true; |
|
| 427 | + if ($opt !== 'false') $opt = true; |
|
| 428 | 428 | else $opt = false; |
| 429 | - return base64_decode($value,$opt); |
|
| 429 | + return base64_decode($value, $opt); |
|
| 430 | 430 | case 'encode_sha1': $cmd = 'sha1'; |
| 431 | 431 | case 'addslashes': |
| 432 | 432 | case 'urldecode': |
@@ -450,18 +450,18 @@ discard block |
||
| 450 | 450 | case 'upper_case': |
| 451 | 451 | return $this->strtoupper($value); |
| 452 | 452 | case 'capitalize': |
| 453 | - $_ = explode(' ',$value); |
|
| 454 | - foreach($_ as $i=>$v) |
|
| 453 | + $_ = explode(' ', $value); |
|
| 454 | + foreach ($_ as $i=>$v) |
|
| 455 | 455 | { |
| 456 | 456 | $_[$i] = ucfirst($v); |
| 457 | 457 | } |
| 458 | - return join(' ',$_); |
|
| 458 | + return join(' ', $_); |
|
| 459 | 459 | case 'zenhan': |
| 460 | - if(empty($opt)) $opt='VKas'; |
|
| 461 | - return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
|
| 460 | + if (empty($opt)) $opt = 'VKas'; |
|
| 461 | + return mb_convert_kana($value, $opt, $modx->config['modx_charset']); |
|
| 462 | 462 | case 'hanzen': |
| 463 | - if(empty($opt)) $opt='VKAS'; |
|
| 464 | - return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
|
| 463 | + if (empty($opt)) $opt = 'VKAS'; |
|
| 464 | + return mb_convert_kana($value, $opt, $modx->config['modx_charset']); |
|
| 465 | 465 | case 'str_shuffle': |
| 466 | 466 | case 'shuffle': |
| 467 | 467 | return $this->str_shuffle($value); |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | return $this->strlen($value); |
| 476 | 476 | case 'count_words': |
| 477 | 477 | $value = trim($value); |
| 478 | - return count(preg_split('/\s+/',$value)); |
|
| 478 | + return count(preg_split('/\s+/', $value)); |
|
| 479 | 479 | case 'str_word_count': |
| 480 | 480 | case 'word_count': |
| 481 | 481 | case 'wordcount': |
@@ -483,55 +483,55 @@ discard block |
||
| 483 | 483 | case 'count_paragraphs': |
| 484 | 484 | $value = trim($value); |
| 485 | 485 | $value = preg_replace('/\r/', '', $value); |
| 486 | - return count(preg_split('/\n+/',$value)); |
|
| 486 | + return count(preg_split('/\n+/', $value)); |
|
| 487 | 487 | case 'strpos': |
| 488 | - if($opt!=0&&empty($opt)) return $value; |
|
| 489 | - return $this->strpos($value,$opt); |
|
| 488 | + if ($opt != 0 && empty($opt)) return $value; |
|
| 489 | + return $this->strpos($value, $opt); |
|
| 490 | 490 | case 'wordwrap': |
| 491 | 491 | // default: 70 |
| 492 | - $wrapat = (int)$opt > 0 ? (int)$opt : 70; |
|
| 492 | + $wrapat = (int) $opt > 0 ? (int) $opt : 70; |
|
| 493 | 493 | if (version_compare(PHP_VERSION, '5.3.0') >= 0) return $this->includeMdfFile('wordwrap'); |
| 494 | - else return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value); |
|
| 494 | + else return preg_replace("@(\b\w+\b)@e", "wordwrap('\\1',\$wrapat,' ',1)", $value); |
|
| 495 | 495 | case 'wrap_text': |
| 496 | - $width = preg_match('/^[1-9][0-9]*$/',$opt) ? $opt : 70; |
|
| 497 | - if($modx->config['manager_language']==='japanese-utf8') { |
|
| 496 | + $width = preg_match('/^[1-9][0-9]*$/', $opt) ? $opt : 70; |
|
| 497 | + if ($modx->config['manager_language'] === 'japanese-utf8') { |
|
| 498 | 498 | $chunk = array(); |
| 499 | - $bt=''; |
|
| 500 | - while($bt!=$value) { |
|
| 499 | + $bt = ''; |
|
| 500 | + while ($bt != $value) { |
|
| 501 | 501 | $bt = $value; |
| 502 | - if($this->strlen($value)<$width) { |
|
| 502 | + if ($this->strlen($value) < $width) { |
|
| 503 | 503 | $chunk[] = $value; |
| 504 | 504 | break; |
| 505 | 505 | } |
| 506 | - $chunk[] = $this->substr($value,0,$width); |
|
| 507 | - $value = $this->substr($value,$width); |
|
| 506 | + $chunk[] = $this->substr($value, 0, $width); |
|
| 507 | + $value = $this->substr($value, $width); |
|
| 508 | 508 | } |
| 509 | - return join("\n",$chunk); |
|
| 509 | + return join("\n", $chunk); |
|
| 510 | 510 | } |
| 511 | 511 | else |
| 512 | - return wordwrap($value,$width,"\n",true); |
|
| 512 | + return wordwrap($value, $width, "\n", true); |
|
| 513 | 513 | case 'substr': |
| 514 | - if(empty($opt)) break; |
|
| 515 | - if(strpos($opt,',')!==false) { |
|
| 516 | - list($b,$e) = explode(',',$opt,2); |
|
| 517 | - return $this->substr($value,$b,(int)$e); |
|
| 514 | + if (empty($opt)) break; |
|
| 515 | + if (strpos($opt, ',') !== false) { |
|
| 516 | + list($b, $e) = explode(',', $opt, 2); |
|
| 517 | + return $this->substr($value, $b, (int) $e); |
|
| 518 | 518 | } |
| 519 | - else return $this->substr($value,$opt); |
|
| 519 | + else return $this->substr($value, $opt); |
|
| 520 | 520 | case 'limit': |
| 521 | 521 | case 'trim_to': // http://www.movabletype.jp/documentation/appendices/modifiers/trim_to.html |
| 522 | - if(strpos($opt,'+')!==false) |
|
| 523 | - list($len,$str) = explode('+',$opt,2); |
|
| 522 | + if (strpos($opt, '+') !== false) |
|
| 523 | + list($len, $str) = explode('+', $opt, 2); |
|
| 524 | 524 | else { |
| 525 | 525 | $len = $opt; |
| 526 | 526 | $str = ''; |
| 527 | 527 | } |
| 528 | - if($len==='') $len = 100; |
|
| 529 | - if(abs($len) > $this->strlen($value)) $str =''; |
|
| 530 | - if(preg_match('/^[1-9][0-9]*$/',$len)) { |
|
| 531 | - return $this->substr($value,0,$len) . $str; |
|
| 528 | + if ($len === '') $len = 100; |
|
| 529 | + if (abs($len) > $this->strlen($value)) $str = ''; |
|
| 530 | + if (preg_match('/^[1-9][0-9]*$/', $len)) { |
|
| 531 | + return $this->substr($value, 0, $len).$str; |
|
| 532 | 532 | } |
| 533 | - elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) { |
|
| 534 | - return $str . $this->substr($value,$len); |
|
| 533 | + elseif (preg_match('/^\-[1-9][0-9]*$/', $len)) { |
|
| 534 | + return $str.$this->substr($value, $len); |
|
| 535 | 535 | } |
| 536 | 536 | break; |
| 537 | 537 | case 'summary': |
@@ -540,81 +540,81 @@ discard block |
||
| 540 | 540 | return $this->includeMdfFile('summary'); |
| 541 | 541 | case 'replace': |
| 542 | 542 | case 'str_replace': |
| 543 | - if(empty($opt) || strpos($opt,',')===false) break; |
|
| 544 | - if (substr_count($opt, ',') ==1) $delim = ','; |
|
| 545 | - elseif(substr_count($opt, '|') ==1) $delim = '|'; |
|
| 546 | - elseif(substr_count($opt, '=>')==1) $delim = '=>'; |
|
| 547 | - elseif(substr_count($opt, '/') ==1) $delim = '/'; |
|
| 543 | + if (empty($opt) || strpos($opt, ',') === false) break; |
|
| 544 | + if (substr_count($opt, ',') == 1) $delim = ','; |
|
| 545 | + elseif (substr_count($opt, '|') == 1) $delim = '|'; |
|
| 546 | + elseif (substr_count($opt, '=>') == 1) $delim = '=>'; |
|
| 547 | + elseif (substr_count($opt, '/') == 1) $delim = '/'; |
|
| 548 | 548 | else break; |
| 549 | - list($s,$r) = explode($delim,$opt); |
|
| 550 | - if($value!=='') return str_replace($s,$r,$value); |
|
| 549 | + list($s, $r) = explode($delim, $opt); |
|
| 550 | + if ($value !== '') return str_replace($s, $r, $value); |
|
| 551 | 551 | break; |
| 552 | 552 | case 'replace_to': |
| 553 | 553 | case 'tpl': |
| 554 | - if($value!=='') return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt); |
|
| 554 | + if ($value !== '') return str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), $value, $opt); |
|
| 555 | 555 | break; |
| 556 | 556 | case 'eachtpl': |
| 557 | - $value = explode('||',$value); |
|
| 557 | + $value = explode('||', $value); |
|
| 558 | 558 | $_ = array(); |
| 559 | - foreach($value as $v) { |
|
| 560 | - $_[] = str_replace(array('[+value+]','[+output+]','{value}','%s'),$v,$opt); |
|
| 559 | + foreach ($value as $v) { |
|
| 560 | + $_[] = str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), $v, $opt); |
|
| 561 | 561 | } |
| 562 | 562 | return join("\n", $_); |
| 563 | 563 | case 'array_pop': |
| 564 | 564 | case 'array_shift': |
| 565 | - if(strpos($value,'||')!==false) $delim = '||'; |
|
| 565 | + if (strpos($value, '||') !== false) $delim = '||'; |
|
| 566 | 566 | else $delim = ','; |
| 567 | - return $cmd(explode($delim,$value)); |
|
| 567 | + return $cmd(explode($delim, $value)); |
|
| 568 | 568 | case 'preg_replace': |
| 569 | 569 | case 'regex_replace': |
| 570 | - if(empty($opt) || strpos($opt,',')===false) break; |
|
| 571 | - list($s,$r) = explode(',',$opt,2); |
|
| 572 | - if($value!=='') return preg_replace($s,$r,$value); |
|
| 570 | + if (empty($opt) || strpos($opt, ',') === false) break; |
|
| 571 | + list($s, $r) = explode(',', $opt, 2); |
|
| 572 | + if ($value !== '') return preg_replace($s, $r, $value); |
|
| 573 | 573 | break; |
| 574 | 574 | case 'cat': |
| 575 | 575 | case 'concatenate': |
| 576 | 576 | case '.': |
| 577 | - if($value!=='') return $value . $opt; |
|
| 577 | + if ($value !== '') return $value.$opt; |
|
| 578 | 578 | break; |
| 579 | 579 | case 'sprintf': |
| 580 | 580 | case 'string_format': |
| 581 | - if($value!=='') return sprintf($opt,$value); |
|
| 581 | + if ($value !== '') return sprintf($opt, $value); |
|
| 582 | 582 | break; |
| 583 | 583 | case 'number_format': |
| 584 | - if($opt=='') $opt = 0; |
|
| 585 | - return number_format($value,$opt); |
|
| 584 | + if ($opt == '') $opt = 0; |
|
| 585 | + return number_format($value, $opt); |
|
| 586 | 586 | case 'money_format': |
| 587 | - setlocale(LC_MONETARY,setlocale(LC_TIME,0)); |
|
| 588 | - if($value!=='') return money_format($opt,(double)$value); |
|
| 587 | + setlocale(LC_MONETARY, setlocale(LC_TIME, 0)); |
|
| 588 | + if ($value !== '') return money_format($opt, (double) $value); |
|
| 589 | 589 | break; |
| 590 | 590 | case 'tobool': |
| 591 | 591 | return boolval($value); |
| 592 | 592 | case 'nl2lf': |
| 593 | - if($value!=='') return str_replace(array("\r\n","\n", "\r"), '\n', $value); |
|
| 593 | + if ($value !== '') return str_replace(array("\r\n", "\n", "\r"), '\n', $value); |
|
| 594 | 594 | break; |
| 595 | 595 | case 'br2nl': |
| 596 | 596 | return preg_replace('@<br[\s/]*>@i', "\n", $value); |
| 597 | 597 | case 'nl2br': |
| 598 | 598 | if (version_compare(PHP_VERSION, '5.3.0', '<')) |
| 599 | 599 | return nl2br($value); |
| 600 | - if($opt!=='') |
|
| 600 | + if ($opt !== '') |
|
| 601 | 601 | { |
| 602 | 602 | $opt = trim($opt); |
| 603 | 603 | $opt = strtolower($opt); |
| 604 | - if($opt==='false') $opt = false; |
|
| 605 | - elseif($opt==='0') $opt = false; |
|
| 604 | + if ($opt === 'false') $opt = false; |
|
| 605 | + elseif ($opt === '0') $opt = false; |
|
| 606 | 606 | else $opt = true; |
| 607 | 607 | } |
| 608 | - elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html') |
|
| 608 | + elseif (isset($modx->config['mce_element_format']) && $modx->config['mce_element_format'] === 'html') |
|
| 609 | 609 | $opt = false; |
| 610 | 610 | else $opt = true; |
| 611 | - return nl2br($value,$opt); |
|
| 611 | + return nl2br($value, $opt); |
|
| 612 | 612 | case 'ltrim': |
| 613 | 613 | case 'rtrim': |
| 614 | 614 | case 'trim': // ref http://mblo.info/modifiers/custom-modifiers/rtrim_opt.html |
| 615 | - if($opt==='') |
|
| 615 | + if ($opt === '') |
|
| 616 | 616 | return $cmd($value); |
| 617 | - else return $cmd($value,$opt); |
|
| 617 | + else return $cmd($value, $opt); |
|
| 618 | 618 | // These are all straight wrappers for PHP functions |
| 619 | 619 | case 'ucfirst': |
| 620 | 620 | case 'lcfirst': |
@@ -625,58 +625,58 @@ discard block |
||
| 625 | 625 | case 'strftime': |
| 626 | 626 | case 'date': |
| 627 | 627 | case 'dateformat': |
| 628 | - if(empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly'); |
|
| 629 | - if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
|
| 630 | - if(strpos($opt,'%')!==false) |
|
| 631 | - return strftime($opt,0+$value); |
|
| 628 | + if (empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly'); |
|
| 629 | + if (!preg_match('@^[0-9]+$@', $value)) $value = strtotime($value); |
|
| 630 | + if (strpos($opt, '%') !== false) |
|
| 631 | + return strftime($opt, 0 + $value); |
|
| 632 | 632 | else |
| 633 | - return date($opt,0+$value); |
|
| 633 | + return date($opt, 0 + $value); |
|
| 634 | 634 | case 'time': |
| 635 | - if(empty($opt)) $opt = '%H:%M'; |
|
| 636 | - if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
|
| 637 | - return strftime($opt,0+$value); |
|
| 635 | + if (empty($opt)) $opt = '%H:%M'; |
|
| 636 | + if (!preg_match('@^[0-9]+$@', $value)) $value = strtotime($value); |
|
| 637 | + return strftime($opt, 0 + $value); |
|
| 638 | 638 | case 'strtotime': |
| 639 | 639 | return strtotime($value); |
| 640 | 640 | ##### mathematical function |
| 641 | 641 | case 'toint': |
| 642 | - return (int)$value; |
|
| 642 | + return (int) $value; |
|
| 643 | 643 | case 'tofloat': |
| 644 | 644 | return floatval($value); |
| 645 | 645 | case 'round': |
| 646 | - if(!$opt) $opt = 0; |
|
| 647 | - return $cmd($value,$opt); |
|
| 646 | + if (!$opt) $opt = 0; |
|
| 647 | + return $cmd($value, $opt); |
|
| 648 | 648 | case 'max': |
| 649 | 649 | case 'min': |
| 650 | - return $cmd(explode(',',$value)); |
|
| 650 | + return $cmd(explode(',', $value)); |
|
| 651 | 651 | case 'floor': |
| 652 | 652 | case 'ceil': |
| 653 | 653 | case 'abs': |
| 654 | 654 | return $cmd($value); |
| 655 | 655 | case 'math': |
| 656 | 656 | case 'calc': |
| 657 | - $value = (int)$value; |
|
| 658 | - if(empty($value)) $value = '0'; |
|
| 659 | - $filter = str_replace(array('[+value+]','[+output+]','{value}','%s'),'?',$opt); |
|
| 660 | - $filter = preg_replace('@([a-zA-Z\n\r\t\s])@','',$filter); |
|
| 661 | - if(strpos($filter,'?')===false) $filter = "?{$filter}"; |
|
| 662 | - $filter = str_replace('?',$value,$filter); |
|
| 657 | + $value = (int) $value; |
|
| 658 | + if (empty($value)) $value = '0'; |
|
| 659 | + $filter = str_replace(array('[+value+]', '[+output+]', '{value}', '%s'), '?', $opt); |
|
| 660 | + $filter = preg_replace('@([a-zA-Z\n\r\t\s])@', '', $filter); |
|
| 661 | + if (strpos($filter, '?') === false) $filter = "?{$filter}"; |
|
| 662 | + $filter = str_replace('?', $value, $filter); |
|
| 663 | 663 | return eval("return {$filter};"); |
| 664 | 664 | case 'count': |
| 665 | - if($value=='') return 0; |
|
| 666 | - $value = explode(',',$value); |
|
| 665 | + if ($value == '') return 0; |
|
| 666 | + $value = explode(',', $value); |
|
| 667 | 667 | return count($value); |
| 668 | 668 | case 'sort': |
| 669 | 669 | case 'rsort': |
| 670 | - if(strpos($value,"\n")!==false) $delim="\n"; |
|
| 670 | + if (strpos($value, "\n") !== false) $delim = "\n"; |
|
| 671 | 671 | else $delim = ','; |
| 672 | - $swap = explode($delim,$value); |
|
| 673 | - if(!$opt) $opt = SORT_REGULAR; |
|
| 672 | + $swap = explode($delim, $value); |
|
| 673 | + if (!$opt) $opt = SORT_REGULAR; |
|
| 674 | 674 | else $opt = constant($opt); |
| 675 | - $cmd($swap,$opt); |
|
| 676 | - return join($delim,$swap); |
|
| 675 | + $cmd($swap, $opt); |
|
| 676 | + return join($delim, $swap); |
|
| 677 | 677 | ##### Resource fields |
| 678 | 678 | case 'id': |
| 679 | - if($opt) return $this->getDocumentObject($opt,$key); |
|
| 679 | + if ($opt) return $this->getDocumentObject($opt, $key); |
|
| 680 | 680 | break; |
| 681 | 681 | case 'type': |
| 682 | 682 | case 'contenttype': |
@@ -713,36 +713,36 @@ discard block |
||
| 713 | 713 | case 'privatemgr': |
| 714 | 714 | case 'content_dispo': |
| 715 | 715 | case 'hidemenu': |
| 716 | - if($cmd==='contenttype') $cmd = 'contentType'; |
|
| 717 | - return $this->getDocumentObject($value,$cmd); |
|
| 716 | + if ($cmd === 'contenttype') $cmd = 'contentType'; |
|
| 717 | + return $this->getDocumentObject($value, $cmd); |
|
| 718 | 718 | case 'title': |
| 719 | - $pagetitle = $this->getDocumentObject($value,'pagetitle'); |
|
| 720 | - $longtitle = $this->getDocumentObject($value,'longtitle'); |
|
| 719 | + $pagetitle = $this->getDocumentObject($value, 'pagetitle'); |
|
| 720 | + $longtitle = $this->getDocumentObject($value, 'longtitle'); |
|
| 721 | 721 | return $longtitle ? $longtitle : $pagetitle; |
| 722 | 722 | case 'shorttitle': |
| 723 | - $pagetitle = $this->getDocumentObject($value,'pagetitle'); |
|
| 724 | - $menutitle = $this->getDocumentObject($value,'menutitle'); |
|
| 723 | + $pagetitle = $this->getDocumentObject($value, 'pagetitle'); |
|
| 724 | + $menutitle = $this->getDocumentObject($value, 'menutitle'); |
|
| 725 | 725 | return $menutitle ? $menutitle : $pagetitle; |
| 726 | 726 | case 'templatename': |
| 727 | - $rs = $modx->db->select('templatename','[+prefix+]site_templates',"id='{$value}'"); |
|
| 727 | + $rs = $modx->db->select('templatename', '[+prefix+]site_templates', "id='{$value}'"); |
|
| 728 | 728 | $templateName = $modx->db->getValue($rs); |
| 729 | 729 | return !$templateName ? '(blank)' : $templateName; |
| 730 | 730 | case 'getfield': |
| 731 | - if(!$opt) $opt = 'content'; |
|
| 732 | - return $modx->getField($opt,$value); |
|
| 731 | + if (!$opt) $opt = 'content'; |
|
| 732 | + return $modx->getField($opt, $value); |
|
| 733 | 733 | case 'children': |
| 734 | 734 | case 'childids': |
| 735 | - if($value=='') $value = 0; // 値がない場合はルートと見なす |
|
| 735 | + if ($value == '') $value = 0; // 値がない場合はルートと見なす |
|
| 736 | 736 | $published = 1; |
| 737 | - if($opt=='') $opt = 'page'; |
|
| 738 | - $_ = explode(',',$opt); |
|
| 737 | + if ($opt == '') $opt = 'page'; |
|
| 738 | + $_ = explode(',', $opt); |
|
| 739 | 739 | $where = array(); |
| 740 | - foreach($_ as $opt) { |
|
| 741 | - switch(trim($opt)) { |
|
| 740 | + foreach ($_ as $opt) { |
|
| 741 | + switch (trim($opt)) { |
|
| 742 | 742 | case 'page'; case '!folder'; case '!isfolder': $where[] = 'sc.isfolder=0'; break; |
| 743 | 743 | case 'folder'; case 'isfolder': $where[] = 'sc.isfolder=1'; break; |
| 744 | - case 'menu'; case 'show_menu': $where[] = 'sc.hidemenu=0'; break; |
|
| 745 | - case '!menu'; case '!show_menu': $where[] = 'sc.hidemenu=1'; break; |
|
| 744 | + case 'menu'; case 'show_menu': $where[] = 'sc.hidemenu=0'; break; |
|
| 745 | + case '!menu'; case '!show_menu': $where[] = 'sc.hidemenu=1'; break; |
|
| 746 | 746 | case 'published': $published = 1; break; |
| 747 | 747 | case '!published': $published = 0; break; |
| 748 | 748 | } |
@@ -750,69 +750,69 @@ discard block |
||
| 750 | 750 | $where = join(' AND ', $where); |
| 751 | 751 | $children = $modx->getDocumentChildren($value, $published, '0', 'id', $where); |
| 752 | 752 | $result = array(); |
| 753 | - foreach((array)$children as $child){ |
|
| 753 | + foreach ((array) $children as $child) { |
|
| 754 | 754 | $result[] = $child['id']; |
| 755 | 755 | } |
| 756 | 756 | return join(',', $result); |
| 757 | 757 | case 'fullurl': |
| 758 | - if(!is_numeric($value)) return $value; |
|
| 758 | + if (!is_numeric($value)) return $value; |
|
| 759 | 759 | return $modx->makeUrl($value); |
| 760 | 760 | case 'makeurl': |
| 761 | - if(!is_numeric($value)) return $value; |
|
| 762 | - if(!$opt) $opt = 'full'; |
|
| 763 | - return $modx->makeUrl($value,'','',$opt); |
|
| 761 | + if (!is_numeric($value)) return $value; |
|
| 762 | + if (!$opt) $opt = 'full'; |
|
| 763 | + return $modx->makeUrl($value, '', '', $opt); |
|
| 764 | 764 | |
| 765 | 765 | ##### File system |
| 766 | 766 | case 'getimageinfo': |
| 767 | 767 | case 'imageinfo': |
| 768 | - if(!is_file($value)) return ''; |
|
| 768 | + if (!is_file($value)) return ''; |
|
| 769 | 769 | $_ = getimagesize($value); |
| 770 | - if(!$_[0]) return ''; |
|
| 770 | + if (!$_[0]) return ''; |
|
| 771 | 771 | $info['width'] = $_[0]; |
| 772 | 772 | $info['height'] = $_[1]; |
| 773 | - if ($_[0] > $_[1]) $info['aspect'] = 'landscape'; |
|
| 774 | - elseif($_[0] < $_[1]) $info['aspect'] = 'portrait'; |
|
| 773 | + if ($_[0] > $_[1]) $info['aspect'] = 'landscape'; |
|
| 774 | + elseif ($_[0] < $_[1]) $info['aspect'] = 'portrait'; |
|
| 775 | 775 | else $info['aspect'] = 'square'; |
| 776 | - switch($_[2]) { |
|
| 776 | + switch ($_[2]) { |
|
| 777 | 777 | case IMAGETYPE_GIF : $info['type'] = 'gif'; break; |
| 778 | 778 | case IMAGETYPE_JPEG : $info['type'] = 'jpg'; break; |
| 779 | 779 | case IMAGETYPE_PNG : $info['type'] = 'png'; break; |
| 780 | 780 | default : $info['type'] = 'unknown'; |
| 781 | 781 | } |
| 782 | 782 | $info['attrib'] = $_[3]; |
| 783 | - switch($opt) { |
|
| 783 | + switch ($opt) { |
|
| 784 | 784 | case 'width' : return $info['width']; |
| 785 | 785 | case 'height': return $info['height']; |
| 786 | 786 | case 'aspect': return $info['aspect']; |
| 787 | 787 | case 'type' : return $info['type']; |
| 788 | 788 | case 'attrib': return $info['attrib']; |
| 789 | - default : return print_r($info,true); |
|
| 789 | + default : return print_r($info, true); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | case 'file_get_contents': |
| 793 | 793 | case 'readfile': |
| 794 | - if(!is_file($value)) return $value; |
|
| 794 | + if (!is_file($value)) return $value; |
|
| 795 | 795 | $value = realpath($value); |
| 796 | - if(strpos($value,MODX_MANAGER_PATH)!==false) exit('Can not read core file'); |
|
| 797 | - $ext = strtolower(substr($value,-4)); |
|
| 798 | - if($ext==='.php') exit('Can not read php file'); |
|
| 799 | - if($ext==='.cgi') exit('Can not read cgi file'); |
|
| 796 | + if (strpos($value, MODX_MANAGER_PATH) !== false) exit('Can not read core file'); |
|
| 797 | + $ext = strtolower(substr($value, -4)); |
|
| 798 | + if ($ext === '.php') exit('Can not read php file'); |
|
| 799 | + if ($ext === '.cgi') exit('Can not read cgi file'); |
|
| 800 | 800 | return file_get_contents($value); |
| 801 | 801 | case 'filesize': |
| 802 | - if($value == '') return ''; |
|
| 802 | + if ($value == '') return ''; |
|
| 803 | 803 | $filename = $value; |
| 804 | 804 | |
| 805 | 805 | $site_url = $modx->config['site_url']; |
| 806 | - if(strpos($filename,$site_url) === 0) |
|
| 807 | - $filename = substr($filename,0,strlen($site_url)); |
|
| 808 | - $filename = trim($filename,'/'); |
|
| 806 | + if (strpos($filename, $site_url) === 0) |
|
| 807 | + $filename = substr($filename, 0, strlen($site_url)); |
|
| 808 | + $filename = trim($filename, '/'); |
|
| 809 | 809 | |
| 810 | - $opt = trim($opt,'/'); |
|
| 811 | - if($opt!=='') $opt .= '/'; |
|
| 810 | + $opt = trim($opt, '/'); |
|
| 811 | + if ($opt !== '') $opt .= '/'; |
|
| 812 | 812 | |
| 813 | 813 | $filename = MODX_BASE_PATH.$opt.$filename; |
| 814 | 814 | |
| 815 | - if(is_file($filename)){ |
|
| 815 | + if (is_file($filename)) { |
|
| 816 | 816 | clearstatcache(); |
| 817 | 817 | $size = filesize($filename); |
| 818 | 818 | return $size; |
@@ -845,10 +845,10 @@ discard block |
||
| 845 | 845 | $this->opt = $cmd; |
| 846 | 846 | return $this->includeMdfFile('moduser'); |
| 847 | 847 | case 'userinfo': |
| 848 | - if(empty($opt)) $this->opt = 'username'; |
|
| 848 | + if (empty($opt)) $this->opt = 'username'; |
|
| 849 | 849 | return $this->includeMdfFile('moduser'); |
| 850 | 850 | case 'webuserinfo': |
| 851 | - if(empty($opt)) $this->opt = 'username'; |
|
| 851 | + if (empty($opt)) $this->opt = 'username'; |
|
| 852 | 852 | $this->value = -$value; |
| 853 | 853 | return $this->includeMdfFile('moduser'); |
| 854 | 854 | ##### Special functions |
@@ -859,27 +859,27 @@ discard block |
||
| 859 | 859 | case 'ifnotempty': |
| 860 | 860 | if (!empty($value)) return $opt; break; |
| 861 | 861 | case 'datagrid': |
| 862 | - include_once(MODX_CORE_PATH . 'controls/datagrid.class.php'); |
|
| 862 | + include_once(MODX_CORE_PATH.'controls/datagrid.class.php'); |
|
| 863 | 863 | $grd = new DataGrid(null, trim($value)); |
| 864 | 864 | $grd->itemStyle = ''; |
| 865 | 865 | $grd->altItemStyle = ''; |
| 866 | - $pos = strpos($value,"\n"); |
|
| 867 | - if($pos) $_ = substr($value,0,$pos); |
|
| 866 | + $pos = strpos($value, "\n"); |
|
| 867 | + if ($pos) $_ = substr($value, 0, $pos); |
|
| 868 | 868 | else $_ = $pos; |
| 869 | - $grd->cdelim = strpos($_,"\t")!==false ? 'tab' : ','; |
|
| 869 | + $grd->cdelim = strpos($_, "\t") !== false ? 'tab' : ','; |
|
| 870 | 870 | return $grd->render(); |
| 871 | 871 | case 'rotate': |
| 872 | 872 | case 'evenodd': |
| 873 | - if(strpos($opt,',')===false) $opt = 'odd,even'; |
|
| 873 | + if (strpos($opt, ',') === false) $opt = 'odd,even'; |
|
| 874 | 874 | $_ = explode(',', $opt); |
| 875 | 875 | $c = count($_); |
| 876 | 876 | $i = $value + $c; |
| 877 | 877 | $i = $i % $c; |
| 878 | 878 | return $_[$i]; |
| 879 | 879 | case 'takeval': |
| 880 | - $arr = explode(",",$opt); |
|
| 880 | + $arr = explode(",", $opt); |
|
| 881 | 881 | $idx = $value; |
| 882 | - if(!is_numeric($idx)) return $value; |
|
| 882 | + if (!is_numeric($idx)) return $value; |
|
| 883 | 883 | return $arr[$idx]; |
| 884 | 884 | case 'getimage': |
| 885 | 885 | return $this->includeMdfFile('getimage'); |
@@ -887,17 +887,17 @@ discard block |
||
| 887 | 887 | return $modx->nicesize($value); |
| 888 | 888 | case 'googlemap': |
| 889 | 889 | case 'googlemaps': |
| 890 | - if(empty($opt)) $opt = 'border:none;width:500px;height:350px;'; |
|
| 890 | + if (empty($opt)) $opt = 'border:none;width:500px;height:350px;'; |
|
| 891 | 891 | $tpl = '<iframe style="[+style+]" src="https://maps.google.co.jp/maps?ll=[+value+]&output=embed&z=15"></iframe>'; |
| 892 | 892 | $ph['style'] = $opt; |
| 893 | 893 | $ph['value'] = $value; |
| 894 | - return $modx->parseText($tpl,$ph); |
|
| 894 | + return $modx->parseText($tpl, $ph); |
|
| 895 | 895 | case 'youtube': |
| 896 | 896 | case 'youtube16x9': |
| 897 | - if(empty($opt)) $opt = 560; |
|
| 898 | - $h = round($opt*0.5625); |
|
| 897 | + if (empty($opt)) $opt = 560; |
|
| 898 | + $h = round($opt * 0.5625); |
|
| 899 | 899 | $tpl = '<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>'; |
| 900 | - return sprintf($tpl,$opt,$h,$value); |
|
| 900 | + return sprintf($tpl, $opt, $h, $value); |
|
| 901 | 901 | //case 'youtube4x3':%s*0.75+25 |
| 902 | 902 | case 'setvar': |
| 903 | 903 | $modx->placeholders[$opt] = $value; |
@@ -927,7 +927,7 @@ discard block |
||
| 927 | 927 | return $value; |
| 928 | 928 | } |
| 929 | 929 | |
| 930 | - public function includeMdfFile($cmd) { |
|
| 930 | + public function includeMdfFile($cmd){ |
|
| 931 | 931 | global $modx; |
| 932 | 932 | $key = $this->key; |
| 933 | 933 | $value = $this->value; |
@@ -938,54 +938,54 @@ discard block |
||
| 938 | 938 | public function getValueFromElement($key, $value, $cmd, $opt) |
| 939 | 939 | { |
| 940 | 940 | global $modx; |
| 941 | - if( isset($modx->snippetCache[$this->elmName]) ) |
|
| 941 | + if (isset($modx->snippetCache[$this->elmName])) |
|
| 942 | 942 | { |
| 943 | 943 | $php = $modx->snippetCache[$this->elmName]; |
| 944 | 944 | } |
| 945 | 945 | else |
| 946 | 946 | { |
| 947 | 947 | $esc_elmName = $modx->db->escape($this->elmName); |
| 948 | - $result = $modx->db->select('snippet','[+prefix+]site_snippets',"name='{$esc_elmName}'"); |
|
| 948 | + $result = $modx->db->select('snippet', '[+prefix+]site_snippets', "name='{$esc_elmName}'"); |
|
| 949 | 949 | $total = $modx->db->getRecordCount($result); |
| 950 | - if($total == 1) |
|
| 950 | + if ($total == 1) |
|
| 951 | 951 | { |
| 952 | 952 | $row = $modx->db->getRow($result); |
| 953 | 953 | $php = $row['snippet']; |
| 954 | 954 | } |
| 955 | - elseif($total == 0) |
|
| 955 | + elseif ($total == 0) |
|
| 956 | 956 | { |
| 957 | 957 | $assets_path = MODX_BASE_PATH.'assets/'; |
| 958 | - if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) |
|
| 958 | + if (is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) |
|
| 959 | 959 | $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php"; |
| 960 | - elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) |
|
| 960 | + elseif (is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) |
|
| 961 | 961 | $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php"; |
| 962 | - elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) |
|
| 962 | + elseif (is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) |
|
| 963 | 963 | $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"; |
| 964 | 964 | else $modifiers_path = false; |
| 965 | 965 | |
| 966 | - if($modifiers_path !== false) { |
|
| 966 | + if ($modifiers_path !== false) { |
|
| 967 | 967 | $php = @file_get_contents($modifiers_path); |
| 968 | 968 | $php = trim($php); |
| 969 | - if(substr($php,0,5)==='<?php') $php = substr($php,6); |
|
| 970 | - if(substr($php,0,2)==='<?') $php = substr($php,3); |
|
| 971 | - if(substr($php,-2)==='?>') $php = substr($php,0,-2); |
|
| 972 | - if($this->elmName!=='') |
|
| 969 | + if (substr($php, 0, 5) === '<?php') $php = substr($php, 6); |
|
| 970 | + if (substr($php, 0, 2) === '<?') $php = substr($php, 3); |
|
| 971 | + if (substr($php, -2) === '?>') $php = substr($php, 0, -2); |
|
| 972 | + if ($this->elmName !== '') |
|
| 973 | 973 | $modx->snippetCache[$this->elmName.'Props'] = ''; |
| 974 | 974 | } |
| 975 | 975 | else |
| 976 | 976 | $php = false; |
| 977 | 977 | } |
| 978 | 978 | else $php = false; |
| 979 | - if($this->elmName!=='') $modx->snippetCache[$this->elmName]= $php; |
|
| 979 | + if ($this->elmName !== '') $modx->snippetCache[$this->elmName] = $php; |
|
| 980 | 980 | } |
| 981 | - if($php==='') $php=false; |
|
| 981 | + if ($php === '') $php = false; |
|
| 982 | 982 | |
| 983 | - if($php===false) $html = $modx->getChunk($this->elmName); |
|
| 983 | + if ($php === false) $html = $modx->getChunk($this->elmName); |
|
| 984 | 984 | else $html = false; |
| 985 | 985 | |
| 986 | 986 | $self = '[+output+]'; |
| 987 | 987 | |
| 988 | - if($php !== false) |
|
| 988 | + if ($php !== false) |
|
| 989 | 989 | { |
| 990 | 990 | ob_start(); |
| 991 | 991 | $options = $opt; |
@@ -998,71 +998,71 @@ discard block |
||
| 998 | 998 | $this->vars['options'] = & $opt; |
| 999 | 999 | $custom = eval($php); |
| 1000 | 1000 | $msg = ob_get_contents(); |
| 1001 | - if($value===$this->bt) $value = $msg . $custom; |
|
| 1001 | + if ($value === $this->bt) $value = $msg.$custom; |
|
| 1002 | 1002 | ob_end_clean(); |
| 1003 | 1003 | } |
| 1004 | - elseif($html!==false && isset($value) && $value!=='') |
|
| 1004 | + elseif ($html !== false && isset($value) && $value !== '') |
|
| 1005 | 1005 | { |
| 1006 | - $html = str_replace(array($self,'[+value+]'), $value, $html); |
|
| 1007 | - $value = str_replace(array('[+options+]','[+param+]'), $opt, $html); |
|
| 1006 | + $html = str_replace(array($self, '[+value+]'), $value, $html); |
|
| 1007 | + $value = str_replace(array('[+options+]', '[+param+]'), $opt, $html); |
|
| 1008 | 1008 | } |
| 1009 | 1009 | else return false; |
| 1010 | 1010 | |
| 1011 | - if($php===false && $html===false && $value!=='' |
|
| 1012 | - && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false)) |
|
| 1011 | + if ($php === false && $html === false && $value !== '' |
|
| 1012 | + && (strpos($cmd, '[+value+]') !== false || strpos($cmd, $self) !== false)) |
|
| 1013 | 1013 | { |
| 1014 | - $value = str_replace(array('[+value+]',$self),$value,$cmd); |
|
| 1014 | + $value = str_replace(array('[+value+]', $self), $value, $cmd); |
|
| 1015 | 1015 | } |
| 1016 | 1016 | return $value; |
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | - public function parseDocumentSource($content='') |
|
| 1019 | + public function parseDocumentSource($content = '') |
|
| 1020 | 1020 | { |
| 1021 | 1021 | global $modx; |
| 1022 | 1022 | |
| 1023 | - if(strpos($content,'[')===false && strpos($content,'{')===false) return $content; |
|
| 1023 | + if (strpos($content, '[') === false && strpos($content, '{') === false) return $content; |
|
| 1024 | 1024 | |
| 1025 | - if(!$modx->maxParserPasses) $modx->maxParserPasses = 10; |
|
| 1026 | - $bt=''; |
|
| 1027 | - $i=0; |
|
| 1028 | - while($bt!==$content) |
|
| 1025 | + if (!$modx->maxParserPasses) $modx->maxParserPasses = 10; |
|
| 1026 | + $bt = ''; |
|
| 1027 | + $i = 0; |
|
| 1028 | + while ($bt !== $content) |
|
| 1029 | 1029 | { |
| 1030 | 1030 | $bt = $content; |
| 1031 | - if(strpos($content,'[*')!==false && $modx->documentIdentifier) |
|
| 1031 | + if (strpos($content, '[*') !== false && $modx->documentIdentifier) |
|
| 1032 | 1032 | $content = $modx->mergeDocumentContent($content); |
| 1033 | - if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content); |
|
| 1034 | - if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content); |
|
| 1035 | - if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content); |
|
| 1036 | - if(strpos($content,'[[')!==false) $content = $modx->evalSnippets($content); |
|
| 1033 | + if (strpos($content, '[(') !== false) $content = $modx->mergeSettingsContent($content); |
|
| 1034 | + if (strpos($content, '{{') !== false) $content = $modx->mergeChunkContent($content); |
|
| 1035 | + if (strpos($content, '[!') !== false) $content = str_replace(array('[!', '!]'), array('[[', ']]'), $content); |
|
| 1036 | + if (strpos($content, '[[') !== false) $content = $modx->evalSnippets($content); |
|
| 1037 | 1037 | |
| 1038 | - if($content===$bt) break; |
|
| 1039 | - if($modx->maxParserPasses < $i) break; |
|
| 1038 | + if ($content === $bt) break; |
|
| 1039 | + if ($modx->maxParserPasses < $i) break; |
|
| 1040 | 1040 | $i++; |
| 1041 | 1041 | } |
| 1042 | 1042 | return $content; |
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | - public function getDocumentObject($target='',$field='pagetitle') |
|
| 1045 | + public function getDocumentObject($target = '', $field = 'pagetitle') |
|
| 1046 | 1046 | { |
| 1047 | 1047 | global $modx; |
| 1048 | 1048 | |
| 1049 | 1049 | $target = trim($target); |
| 1050 | - if(empty($target)) $target = $modx->config['site_start']; |
|
| 1051 | - if(preg_match('@^[1-9][0-9]*$@',$target)) $method='id'; |
|
| 1050 | + if (empty($target)) $target = $modx->config['site_start']; |
|
| 1051 | + if (preg_match('@^[1-9][0-9]*$@', $target)) $method = 'id'; |
|
| 1052 | 1052 | else $method = 'alias'; |
| 1053 | 1053 | |
| 1054 | - if(!isset($this->documentObject[$target])) |
|
| 1054 | + if (!isset($this->documentObject[$target])) |
|
| 1055 | 1055 | { |
| 1056 | - $this->documentObject[$target] = $modx->getDocumentObject($method,$target,'direct'); |
|
| 1056 | + $this->documentObject[$target] = $modx->getDocumentObject($method, $target, 'direct'); |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | - if($this->documentObject[$target]['publishedon']==='0') |
|
| 1059 | + if ($this->documentObject[$target]['publishedon'] === '0') |
|
| 1060 | 1060 | return ''; |
| 1061 | - elseif(isset($this->documentObject[$target][$field])) |
|
| 1061 | + elseif (isset($this->documentObject[$target][$field])) |
|
| 1062 | 1062 | { |
| 1063 | - if(is_array($this->documentObject[$target][$field])) |
|
| 1063 | + if (is_array($this->documentObject[$target][$field])) |
|
| 1064 | 1064 | { |
| 1065 | - $a = $modx->getTemplateVarOutput($field,$target); |
|
| 1065 | + $a = $modx->getTemplateVarOutput($field, $target); |
|
| 1066 | 1066 | $this->documentObject[$target][$field] = $a[$field]; |
| 1067 | 1067 | } |
| 1068 | 1068 | } |
@@ -1071,8 +1071,8 @@ discard block |
||
| 1071 | 1071 | return $this->documentObject[$target][$field]; |
| 1072 | 1072 | } |
| 1073 | 1073 | |
| 1074 | - public function setPlaceholders($value = '', $key = '', $path = '') { |
|
| 1075 | - if($path!=='') $key = "{$path}.{$key}"; |
|
| 1074 | + public function setPlaceholders($value = '', $key = '', $path = ''){ |
|
| 1075 | + if ($path !== '') $key = "{$path}.{$key}"; |
|
| 1076 | 1076 | if (is_array($value)) { |
| 1077 | 1077 | foreach ($value as $subkey => $subval) { |
| 1078 | 1078 | $this->setPlaceholders($subval, $subkey, $key); |
@@ -1082,77 +1082,77 @@ discard block |
||
| 1082 | 1082 | } |
| 1083 | 1083 | |
| 1084 | 1084 | // Sets a placeholder variable which can only be access by Modifiers |
| 1085 | - public function setModifiersVariable($key, $value) { |
|
| 1085 | + public function setModifiersVariable($key, $value){ |
|
| 1086 | 1086 | if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value; |
| 1087 | 1087 | } |
| 1088 | 1088 | |
| 1089 | 1089 | //mbstring |
| 1090 | - public function substr($str, $s, $l = null) { |
|
| 1090 | + public function substr($str, $s, $l = null){ |
|
| 1091 | 1091 | global $modx; |
| 1092 | - if(is_null($l)) $l = $this->strlen($str); |
|
| 1092 | + if (is_null($l)) $l = $this->strlen($str); |
|
| 1093 | 1093 | if (function_exists('mb_substr')) |
| 1094 | 1094 | { |
| 1095 | - if(strpos($str,"\r")!==false) |
|
| 1096 | - $str = str_replace(array("\r\n","\r"), "\n", $str); |
|
| 1095 | + if (strpos($str, "\r") !== false) |
|
| 1096 | + $str = str_replace(array("\r\n", "\r"), "\n", $str); |
|
| 1097 | 1097 | return mb_substr($str, $s, $l, $modx->config['modx_charset']); |
| 1098 | 1098 | } |
| 1099 | 1099 | return substr($str, $s, $l); |
| 1100 | 1100 | } |
| 1101 | - public function strpos($haystack,$needle,$offset=0) { |
|
| 1101 | + public function strpos($haystack, $needle, $offset = 0){ |
|
| 1102 | 1102 | global $modx; |
| 1103 | - if (function_exists('mb_strpos')) return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']); |
|
| 1104 | - return strpos($haystack,$needle,$offset); |
|
| 1103 | + if (function_exists('mb_strpos')) return mb_strpos($haystack, $needle, $offset, $modx->config['modx_charset']); |
|
| 1104 | + return strpos($haystack, $needle, $offset); |
|
| 1105 | 1105 | } |
| 1106 | - public function strlen($str) { |
|
| 1106 | + public function strlen($str){ |
|
| 1107 | 1107 | global $modx; |
| 1108 | - if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']); |
|
| 1108 | + if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str), $modx->config['modx_charset']); |
|
| 1109 | 1109 | return strlen($str); |
| 1110 | 1110 | } |
| 1111 | - public function strtolower($str) { |
|
| 1111 | + public function strtolower($str){ |
|
| 1112 | 1112 | if (function_exists('mb_strtolower')) return mb_strtolower($str); |
| 1113 | 1113 | return strtolower($str); |
| 1114 | 1114 | } |
| 1115 | - public function strtoupper($str) { |
|
| 1115 | + public function strtoupper($str){ |
|
| 1116 | 1116 | if (function_exists('mb_strtoupper')) return mb_strtoupper($str); |
| 1117 | 1117 | return strtoupper($str); |
| 1118 | 1118 | } |
| 1119 | - public function ucfirst($str) { |
|
| 1119 | + public function ucfirst($str){ |
|
| 1120 | 1120 | if (function_exists('mb_strtoupper')) |
| 1121 | 1121 | return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
| 1122 | 1122 | return ucfirst($str); |
| 1123 | 1123 | } |
| 1124 | - public function lcfirst($str) { |
|
| 1124 | + public function lcfirst($str){ |
|
| 1125 | 1125 | if (function_exists('mb_strtolower')) |
| 1126 | 1126 | return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
| 1127 | 1127 | return lcfirst($str); |
| 1128 | 1128 | } |
| 1129 | - public function ucwords($str) { |
|
| 1129 | + public function ucwords($str){ |
|
| 1130 | 1130 | if (function_exists('mb_convert_case')) |
| 1131 | 1131 | return mb_convert_case($str, MB_CASE_TITLE); |
| 1132 | 1132 | return ucwords($str); |
| 1133 | 1133 | } |
| 1134 | - public function strrev($str) { |
|
| 1134 | + public function strrev($str){ |
|
| 1135 | 1135 | preg_match_all('/./us', $str, $ar); |
| 1136 | 1136 | return join(array_reverse($ar[0])); |
| 1137 | 1137 | } |
| 1138 | - public function str_shuffle($str) { |
|
| 1138 | + public function str_shuffle($str){ |
|
| 1139 | 1139 | preg_match_all('/./us', $str, $ar); |
| 1140 | 1140 | shuffle($ar[0]); |
| 1141 | 1141 | return join($ar[0]); |
| 1142 | 1142 | } |
| 1143 | - public function str_word_count($str) { |
|
| 1144 | - return count(preg_split('~[^\p{L}\p{N}\']+~u',$str)); |
|
| 1143 | + public function str_word_count($str){ |
|
| 1144 | + return count(preg_split('~[^\p{L}\p{N}\']+~u', $str)); |
|
| 1145 | 1145 | } |
| 1146 | - public function strip_tags($value,$params='') { |
|
| 1146 | + public function strip_tags($value, $params = ''){ |
|
| 1147 | 1147 | global $modx; |
| 1148 | 1148 | |
| 1149 | - if(stripos($params,'style')===false && stripos($value,'</style>')!==false) { |
|
| 1149 | + if (stripos($params, 'style') === false && stripos($value, '</style>') !== false) { |
|
| 1150 | 1150 | $value = preg_replace('@<style.*?>.*?</style>@is', '', $value); |
| 1151 | 1151 | } |
| 1152 | - if(stripos($params,'script')===false && stripos($value,'</script>')!==false) { |
|
| 1152 | + if (stripos($params, 'script') === false && stripos($value, '</script>') !== false) { |
|
| 1153 | 1153 | $value = preg_replace('@<script.*?>.*?</script>@is', '', $value); |
| 1154 | 1154 | } |
| 1155 | 1155 | |
| 1156 | - return trim(strip_tags($value,$params)); |
|
| 1156 | + return trim(strip_tags($value, $params)); |
|
| 1157 | 1157 | } |
| 1158 | 1158 | } |
@@ -1,8 +1,11 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if(!defined('MODX_CORE_PATH')) define('MODX_CORE_PATH', MODX_MANAGER_PATH.'includes/'); |
|
| 3 | +if(!defined('MODX_CORE_PATH')) { |
|
| 4 | + define('MODX_CORE_PATH', MODX_MANAGER_PATH.'includes/'); |
|
| 5 | +} |
|
| 4 | 6 | |
| 5 | -class MODIFIERS { |
|
| 7 | +class MODIFIERS |
|
| 8 | +{ |
|
| 6 | 9 | |
| 7 | 10 | public $placeholders = array(); |
| 8 | 11 | public $vars = array(); |
@@ -26,14 +29,18 @@ discard block |
||
| 26 | 29 | { |
| 27 | 30 | global $modx; |
| 28 | 31 | |
| 29 | - if (function_exists('mb_internal_encoding')) mb_internal_encoding($modx->config['modx_charset']); |
|
| 32 | + if (function_exists('mb_internal_encoding')) { |
|
| 33 | + mb_internal_encoding($modx->config['modx_charset']); |
|
| 34 | + } |
|
| 30 | 35 | $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 | 36 | } |
| 32 | 37 | |
| 33 | 38 | public function phxFilter($key,$value,$modifiers) |
| 34 | 39 | { |
| 35 | 40 | global $modx; |
| 36 | - if(substr($modifiers,0,3)!=='id(') $value = $this->parseDocumentSource($value); |
|
| 41 | + if(substr($modifiers,0,3)!=='id(') { |
|
| 42 | + $value = $this->parseDocumentSource($value); |
|
| 43 | + } |
|
| 37 | 44 | $this->srcValue = $value; |
| 38 | 45 | $modifiers = trim($modifiers); |
| 39 | 46 | $modifiers = ':'.trim($modifiers,':'); |
@@ -51,63 +58,81 @@ discard block |
||
| 51 | 58 | return $value; |
| 52 | 59 | } |
| 53 | 60 | |
| 54 | - public function _getDelim($mode,$modifiers) { |
|
| 61 | + public function _getDelim($mode,$modifiers) |
|
| 62 | + { |
|
| 55 | 63 | $c = substr($modifiers,0,1); |
| 56 | - if(!in_array($c, array('"', "'", '`')) ) return false; |
|
| 64 | + if(!in_array($c, array('"', "'", '`')) ) { |
|
| 65 | + return false; |
|
| 66 | + } |
|
| 57 | 67 | |
| 58 | 68 | $modifiers = substr($modifiers,1); |
| 59 | 69 | $closure = $mode=='(' ? "{$c})" : $c; |
| 60 | - if(strpos($modifiers, $closure)===false) return false; |
|
| 70 | + if(strpos($modifiers, $closure)===false) { |
|
| 71 | + return false; |
|
| 72 | + } |
|
| 61 | 73 | |
| 62 | 74 | return $c; |
| 63 | 75 | } |
| 64 | 76 | |
| 65 | - public function _getOpt($mode,$delim,$modifiers) { |
|
| 77 | + public function _getOpt($mode,$delim,$modifiers) |
|
| 78 | + { |
|
| 66 | 79 | if($delim) { |
| 67 | - if($mode=='(') return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1); |
|
| 80 | + if($mode=='(') { |
|
| 81 | + return substr($modifiers,1,strpos($modifiers, $delim . ')' )-1); |
|
| 82 | + } |
|
| 68 | 83 | |
| 69 | 84 | return substr($modifiers,1,strpos($modifiers,$delim,1)-1); |
| 70 | - } |
|
| 71 | - else { |
|
| 72 | - if($mode=='(') return substr($modifiers,0,strpos($modifiers, ')') ); |
|
| 85 | + } else { |
|
| 86 | + if($mode=='(') { |
|
| 87 | + return substr($modifiers,0,strpos($modifiers, ')') ); |
|
| 88 | + } |
|
| 73 | 89 | |
| 74 | 90 | $chars = str_split($modifiers); |
| 75 | 91 | $opt=''; |
| 76 | 92 | foreach($chars as $c) { |
| 77 | - if($c==':' || $c==')') break; |
|
| 93 | + if($c==':' || $c==')') { |
|
| 94 | + break; |
|
| 95 | + } |
|
| 78 | 96 | $opt .=$c; |
| 79 | 97 | } |
| 80 | 98 | return $opt; |
| 81 | 99 | } |
| 82 | 100 | } |
| 83 | - public function _getRemainModifiers($mode,$delim,$modifiers) { |
|
| 101 | + public function _getRemainModifiers($mode,$delim,$modifiers) |
|
| 102 | + { |
|
| 84 | 103 | if($delim) { |
| 85 | - if($mode=='(') |
|
| 86 | - return $this->_fetchContent($modifiers, $delim . ')'); |
|
| 87 | - else { |
|
| 104 | + if($mode=='(') { |
|
| 105 | + return $this->_fetchContent($modifiers, $delim . ')'); |
|
| 106 | + } else { |
|
| 88 | 107 | $modifiers = trim($modifiers); |
| 89 | 108 | $modifiers = substr($modifiers,1); |
| 90 | 109 | return $this->_fetchContent($modifiers, $delim); |
| 91 | 110 | } |
| 92 | - } |
|
| 93 | - else { |
|
| 94 | - if($mode=='(') return $this->_fetchContent($modifiers, ')'); |
|
| 111 | + } else { |
|
| 112 | + if($mode=='(') { |
|
| 113 | + return $this->_fetchContent($modifiers, ')'); |
|
| 114 | + } |
|
| 95 | 115 | $chars = str_split($modifiers); |
| 96 | 116 | foreach($chars as $c) { |
| 97 | - if($c==':') return $modifiers; |
|
| 98 | - else $modifiers = substr($modifiers,1); |
|
| 117 | + if($c==':') { |
|
| 118 | + return $modifiers; |
|
| 119 | + } else { |
|
| 120 | + $modifiers = substr($modifiers,1); |
|
| 121 | + } |
|
| 99 | 122 | } |
| 100 | 123 | return $modifiers; |
| 101 | 124 | } |
| 102 | 125 | } |
| 103 | 126 | |
| 104 | - public function _fetchContent($string,$delim) { |
|
| 127 | + public function _fetchContent($string,$delim) |
|
| 128 | + { |
|
| 105 | 129 | $len = strlen($delim); |
| 106 | 130 | $string = $this->parseDocumentSource($string); |
| 107 | 131 | return substr($string,strpos($string, $delim)+$len); |
| 108 | 132 | } |
| 109 | 133 | |
| 110 | - public function splitEachModifiers($modifiers) { |
|
| 134 | + public function splitEachModifiers($modifiers) |
|
| 135 | + { |
|
| 111 | 136 | global $modx; |
| 112 | 137 | |
| 113 | 138 | $cmd = ''; |
@@ -118,11 +143,15 @@ discard block |
||
| 118 | 143 | $c = substr($modifiers,0,1); |
| 119 | 144 | $modifiers = substr($modifiers,1); |
| 120 | 145 | |
| 121 | - if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { // :=, :!=, :<=, :>=, :!<=, :!>= |
|
| 146 | + if($c===':' && preg_match('@^(!?[<>=]{1,2})@', $modifiers, $match)) { |
|
| 147 | +// :=, :!=, :<=, :>=, :!<=, :!>= |
|
| 122 | 148 | $c = substr($modifiers,strlen($match[1]),1); |
| 123 | 149 | $debuginfo = "#i=0 #c=[{$c}] #m=[{$modifiers}]"; |
| 124 | - if($c==='(') $modifiers = substr($modifiers,strlen($match[1])+1); |
|
| 125 | - else $modifiers = substr($modifiers,strlen($match[1])); |
|
| 150 | + if($c==='(') { |
|
| 151 | + $modifiers = substr($modifiers,strlen($match[1])+1); |
|
| 152 | + } else { |
|
| 153 | + $modifiers = substr($modifiers,strlen($match[1])); |
|
| 154 | + } |
|
| 126 | 155 | |
| 127 | 156 | $delim = $this->_getDelim($c,$modifiers); |
| 128 | 157 | $opt = $this->_getOpt($c,$delim,$modifiers); |
@@ -130,13 +159,12 @@ discard block |
||
| 130 | 159 | |
| 131 | 160 | $result[]=array('cmd'=>trim($match[1]),'opt'=>$opt,'debuginfo'=>$debuginfo); |
| 132 | 161 | $cmd = ''; |
| 133 | - } |
|
| 134 | - elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { // :+3, :-3, :*3 ... |
|
| 162 | + } elseif(in_array($c,array('+','-','*','/')) && preg_match('@^[0-9]+@', $modifiers, $match)) { |
|
| 163 | +// :+3, :-3, :*3 ... |
|
| 135 | 164 | $modifiers = substr($modifiers,strlen($match[0])); |
| 136 | 165 | $result[]=array('cmd'=>'math','opt'=>'%s'.$c.$match[0]); |
| 137 | 166 | $cmd = ''; |
| 138 | - } |
|
| 139 | - elseif($c==='(' || $c==='=') { |
|
| 167 | + } elseif($c==='(' || $c==='=') { |
|
| 140 | 168 | $modifiers = $m1 = trim($modifiers); |
| 141 | 169 | $delim = $this->_getDelim($c,$modifiers); |
| 142 | 170 | $opt = $this->_getOpt($c,$delim,$modifiers); |
@@ -146,29 +174,29 @@ discard block |
||
| 146 | 174 | $result[]=array('cmd'=>trim($cmd),'opt'=>$opt,'debuginfo'=>$debuginfo); |
| 147 | 175 | |
| 148 | 176 | $cmd = ''; |
| 149 | - } |
|
| 150 | - elseif($c==':') { |
|
| 177 | + } elseif($c==':') { |
|
| 151 | 178 | $debuginfo = "#i=2 #c=[{$c}] #m=[{$modifiers}]"; |
| 152 | - if($cmd!=='') $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
|
| 179 | + if($cmd!=='') { |
|
| 180 | + $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
|
| 181 | + } |
|
| 153 | 182 | |
| 154 | 183 | $cmd = ''; |
| 155 | - } |
|
| 156 | - elseif(trim($modifiers)=='' && trim($cmd)!=='') { |
|
| 184 | + } elseif(trim($modifiers)=='' && trim($cmd)!=='') { |
|
| 157 | 185 | $debuginfo = "#i=3 #c=[{$c}] #m=[{$modifiers}]"; |
| 158 | 186 | $cmd .= $c; |
| 159 | 187 | $result[]=array('cmd'=>trim($cmd),'opt'=>'','debuginfo'=>$debuginfo); |
| 160 | 188 | |
| 161 | 189 | break; |
| 162 | - } |
|
| 163 | - else { |
|
| 190 | + } else { |
|
| 164 | 191 | $cmd .= $c; |
| 165 | 192 | } |
| 166 | 193 | } |
| 167 | 194 | |
| 168 | - if(empty($result)) return array(); |
|
| 195 | + if(empty($result)) { |
|
| 196 | + return array(); |
|
| 197 | + } |
|
| 169 | 198 | |
| 170 | - foreach($result as $i=>$a) |
|
| 171 | - { |
|
| 199 | + foreach($result as $i=>$a) { |
|
| 172 | 200 | $a['opt'] = $this->parseDocumentSource($a['opt']); |
| 173 | 201 | $result[$i]['opt'] = $modx->mergePlaceholderContent($a['opt'],$this->placeholders); |
| 174 | 202 | } |
@@ -181,22 +209,23 @@ discard block |
||
| 181 | 209 | global $modx; |
| 182 | 210 | $lastKey = ''; |
| 183 | 211 | $cacheKey = md5(sprintf('parsePhx#%s#%s#%s',$key,$value,print_r($modifiers,true))); |
| 184 | - if(isset($this->tmpCache[$cacheKey])) return $this->tmpCache[$cacheKey]; |
|
| 185 | - if(empty($modifiers)) return ''; |
|
| 212 | + if(isset($this->tmpCache[$cacheKey])) { |
|
| 213 | + return $this->tmpCache[$cacheKey]; |
|
| 214 | + } |
|
| 215 | + if(empty($modifiers)) { |
|
| 216 | + return ''; |
|
| 217 | + } |
|
| 186 | 218 | |
| 187 | - foreach($modifiers as $m) |
|
| 188 | - { |
|
| 219 | + foreach($modifiers as $m) { |
|
| 189 | 220 | $lastKey = strtolower($m['cmd']); |
| 190 | 221 | } |
| 191 | 222 | $_ = explode(',',$this->condModifiers); |
| 192 | - if(in_array($lastKey,$_)) |
|
| 193 | - { |
|
| 223 | + if(in_array($lastKey,$_)) { |
|
| 194 | 224 | $modifiers[] = array('cmd'=>'then','opt'=>'1'); |
| 195 | 225 | $modifiers[] = array('cmd'=>'else','opt'=>'0'); |
| 196 | 226 | } |
| 197 | 227 | |
| 198 | - foreach($modifiers as $i=>$a) |
|
| 199 | - { |
|
| 228 | + foreach($modifiers as $i=>$a) { |
|
| 200 | 229 | $value = $this->Filter($key,$value, $a['cmd'], $a['opt']); |
| 201 | 230 | } |
| 202 | 231 | $this->tmpCache[$cacheKey] = $value; |
@@ -208,25 +237,32 @@ discard block |
||
| 208 | 237 | { |
| 209 | 238 | global $modx; |
| 210 | 239 | |
| 211 | - if($key==='documentObject') $value = $modx->documentIdentifier; |
|
| 240 | + if($key==='documentObject') { |
|
| 241 | + $value = $modx->documentIdentifier; |
|
| 242 | + } |
|
| 212 | 243 | $cmd = $this->parseDocumentSource($cmd); |
| 213 | - if(preg_match('@^[1-9][/0-9]*$@',$cmd)) |
|
| 214 | - { |
|
| 215 | - if(strpos($cmd,'/')!==false) |
|
| 216 | - $cmd = $this->substr($cmd,strrpos($cmd,'/')+1); |
|
| 244 | + if(preg_match('@^[1-9][/0-9]*$@',$cmd)) { |
|
| 245 | + if(strpos($cmd,'/')!==false) { |
|
| 246 | + $cmd = $this->substr($cmd,strrpos($cmd,'/')+1); |
|
| 247 | + } |
|
| 217 | 248 | $opt = $cmd; |
| 218 | 249 | $cmd = 'id'; |
| 219 | 250 | } |
| 220 | 251 | |
| 221 | - if(isset($modx->snippetCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
| 222 | - elseif(isset($modx->chunkCache["phx:{$cmd}"])) $this->elmName = "phx:{$cmd}"; |
|
| 223 | - else $this->elmName = ''; |
|
| 252 | + if(isset($modx->snippetCache["phx:{$cmd}"])) { |
|
| 253 | + $this->elmName = "phx:{$cmd}"; |
|
| 254 | + } elseif(isset($modx->chunkCache["phx:{$cmd}"])) { |
|
| 255 | + $this->elmName = "phx:{$cmd}"; |
|
| 256 | + } else { |
|
| 257 | + $this->elmName = ''; |
|
| 258 | + } |
|
| 224 | 259 | |
| 225 | 260 | $cmd = strtolower($cmd); |
| 226 | - if($this->elmName!=='') |
|
| 227 | - $value = $this->getValueFromElement($key, $value, $cmd, $opt); |
|
| 228 | - else |
|
| 229 | - $value = $this->getValueFromPreset($key, $value, $cmd, $opt); |
|
| 261 | + if($this->elmName!=='') { |
|
| 262 | + $value = $this->getValueFromElement($key, $value, $cmd, $opt); |
|
| 263 | + } else { |
|
| 264 | + $value = $this->getValueFromPreset($key, $value, $cmd, $opt); |
|
| 265 | + } |
|
| 230 | 266 | |
| 231 | 267 | $value = str_replace('[+key+]', $key, $value); |
| 232 | 268 | |
@@ -235,29 +271,37 @@ discard block |
||
| 235 | 271 | |
| 236 | 272 | public function isEmpty($cmd,$value) |
| 237 | 273 | { |
| 238 | - if($value!=='') return false; |
|
| 274 | + if($value!=='') { |
|
| 275 | + return false; |
|
| 276 | + } |
|
| 239 | 277 | |
| 240 | 278 | $_ = explode(',', $this->condModifiers . ',_default,default,if,input,or,and,show,this,select,switch,then,else,id,ifempty,smart_desc,smart_description,summary'); |
| 241 | - if(in_array($cmd,$_)) return false; |
|
| 242 | - else return true; |
|
| 279 | + if(in_array($cmd,$_)) { |
|
| 280 | + return false; |
|
| 281 | + } else { |
|
| 282 | + return true; |
|
| 283 | + } |
|
| 243 | 284 | } |
| 244 | 285 | |
| 245 | 286 | public function getValueFromPreset($key, $value, $cmd, $opt) |
| 246 | 287 | { |
| 247 | 288 | global $modx; |
| 248 | 289 | |
| 249 | - if($this->isEmpty($cmd,$value)) return ''; |
|
| 290 | + if($this->isEmpty($cmd,$value)) { |
|
| 291 | + return ''; |
|
| 292 | + } |
|
| 250 | 293 | |
| 251 | 294 | $this->key = $key; |
| 252 | 295 | $this->value = $value; |
| 253 | 296 | $this->opt = $opt; |
| 254 | 297 | |
| 255 | - switch ($cmd) |
|
| 256 | - { |
|
| 298 | + switch ($cmd) { |
|
| 257 | 299 | ##### Conditional Modifiers |
| 258 | 300 | case 'input': |
| 259 | 301 | case 'if': |
| 260 | - if(!$opt) return $value; |
|
| 302 | + if(!$opt) { |
|
| 303 | + return $value; |
|
| 304 | + } |
|
| 261 | 305 | return $opt; |
| 262 | 306 | case '=': |
| 263 | 307 | case 'eq': |
@@ -318,14 +362,24 @@ discard block |
||
| 318 | 362 | case 'file_exists': |
| 319 | 363 | case 'is_readable': |
| 320 | 364 | case 'is_writable': |
| 321 | - if(!$opt) $path = $value; |
|
| 322 | - else $path = $opt; |
|
| 323 | - if(strpos($path,MODX_MANAGER_PATH)!==false) exit('Can not read core path'); |
|
| 324 | - if(strpos($path,$modx->config['base_path'])===false) $path = ltrim($path,'/'); |
|
| 365 | + if(!$opt) { |
|
| 366 | + $path = $value; |
|
| 367 | + } else { |
|
| 368 | + $path = $opt; |
|
| 369 | + } |
|
| 370 | + if(strpos($path,MODX_MANAGER_PATH)!==false) { |
|
| 371 | + exit('Can not read core path'); |
|
| 372 | + } |
|
| 373 | + if(strpos($path,$modx->config['base_path'])===false) { |
|
| 374 | + $path = ltrim($path,'/'); |
|
| 375 | + } |
|
| 325 | 376 | $this->condition[] = (int)($cmd($path)!==false);break; |
| 326 | 377 | case 'is_image': |
| 327 | - if(!$opt) $path = $value; |
|
| 328 | - else $path = $opt; |
|
| 378 | + if(!$opt) { |
|
| 379 | + $path = $value; |
|
| 380 | + } else { |
|
| 381 | + $path = $opt; |
|
| 382 | + } |
|
| 329 | 383 | if(!is_file($path)) {$this->condition[]='0';break;} |
| 330 | 384 | $_ = getimagesize($path); |
| 331 | 385 | $this->condition[] = (int)($_[0]);break; |
@@ -348,17 +402,23 @@ discard block |
||
| 348 | 402 | case 'this': |
| 349 | 403 | $conditional = join(' ',$this->condition); |
| 350 | 404 | $isvalid = (int)(eval("return ({$conditional});")); |
| 351 | - if ($isvalid) return $this->srcValue; |
|
| 405 | + if ($isvalid) { |
|
| 406 | + return $this->srcValue; |
|
| 407 | + } |
|
| 352 | 408 | return NULL; |
| 353 | 409 | case 'then': |
| 354 | 410 | $conditional = join(' ',$this->condition); |
| 355 | 411 | $isvalid = (int)eval("return ({$conditional});"); |
| 356 | - if ($isvalid) return $opt; |
|
| 412 | + if ($isvalid) { |
|
| 413 | + return $opt; |
|
| 414 | + } |
|
| 357 | 415 | return null; |
| 358 | 416 | case 'else': |
| 359 | 417 | $conditional = join(' ',$this->condition); |
| 360 | 418 | $isvalid = (int)eval("return ({$conditional});"); |
| 361 | - if (!$isvalid) return $opt; |
|
| 419 | + if (!$isvalid) { |
|
| 420 | + return $opt; |
|
| 421 | + } |
|
| 362 | 422 | break; |
| 363 | 423 | case 'select': |
| 364 | 424 | case 'switch': |
@@ -369,8 +429,11 @@ discard block |
||
| 369 | 429 | $mi = explode('=',$raw[$m],2); |
| 370 | 430 | $map[$mi[0]] = $mi[1]; |
| 371 | 431 | } |
| 372 | - if(isset($map[$value])) return $map[$value]; |
|
| 373 | - else return ''; |
|
| 432 | + if(isset($map[$value])) { |
|
| 433 | + return $map[$value]; |
|
| 434 | + } else { |
|
| 435 | + return ''; |
|
| 436 | + } |
|
| 374 | 437 | ##### End of Conditional Modifiers |
| 375 | 438 | |
| 376 | 439 | ##### Encode / Decode / Hash / Escape |
@@ -396,24 +459,25 @@ discard block |
||
| 396 | 459 | case 'spam_protect': |
| 397 | 460 | return str_replace(array('@','.'),array('@','.'),$value); |
| 398 | 461 | case 'strip': |
| 399 | - if($opt==='') $opt = ' '; |
|
| 462 | + if($opt==='') { |
|
| 463 | + $opt = ' '; |
|
| 464 | + } |
|
| 400 | 465 | return preg_replace('/[\n\r\t\s]+/', $opt, $value); |
| 401 | 466 | case 'strip_linefeeds': |
| 402 | 467 | return str_replace(array("\n","\r"), '', $value); |
| 403 | 468 | case 'notags': |
| 404 | 469 | case 'strip_tags': |
| 405 | 470 | case 'remove_html': |
| 406 | - if($opt!=='') |
|
| 407 | - { |
|
| 471 | + if($opt!=='') { |
|
| 408 | 472 | $param = array(); |
| 409 | - foreach(explode(',',$opt) as $v) |
|
| 410 | - { |
|
| 473 | + foreach(explode(',',$opt) as $v) { |
|
| 411 | 474 | $v = trim($v,'</> '); |
| 412 | 475 | $param[] = "<{$v}>"; |
| 413 | 476 | } |
| 414 | 477 | $params = join(',',$param); |
| 478 | + } else { |
|
| 479 | + $params = ''; |
|
| 415 | 480 | } |
| 416 | - else $params = ''; |
|
| 417 | 481 | if(!strpos($params,'<br>')===false) { |
| 418 | 482 | $value = preg_replace('@(<br[ /]*>)\n@','$1',$value); |
| 419 | 483 | $value = preg_replace('@<br[ /]*>@',"\n",$value); |
@@ -424,8 +488,11 @@ discard block |
||
| 424 | 488 | case 'encode_url': |
| 425 | 489 | return urlencode($value); |
| 426 | 490 | case 'base64_decode': |
| 427 | - if($opt!=='false') $opt = true; |
|
| 428 | - else $opt = false; |
|
| 491 | + if($opt!=='false') { |
|
| 492 | + $opt = true; |
|
| 493 | + } else { |
|
| 494 | + $opt = false; |
|
| 495 | + } |
|
| 429 | 496 | return base64_decode($value,$opt); |
| 430 | 497 | case 'encode_sha1': $cmd = 'sha1'; |
| 431 | 498 | case 'addslashes': |
@@ -451,16 +518,19 @@ discard block |
||
| 451 | 518 | return $this->strtoupper($value); |
| 452 | 519 | case 'capitalize': |
| 453 | 520 | $_ = explode(' ',$value); |
| 454 | - foreach($_ as $i=>$v) |
|
| 455 | - { |
|
| 521 | + foreach($_ as $i=>$v) { |
|
| 456 | 522 | $_[$i] = ucfirst($v); |
| 457 | 523 | } |
| 458 | 524 | return join(' ',$_); |
| 459 | 525 | case 'zenhan': |
| 460 | - if(empty($opt)) $opt='VKas'; |
|
| 526 | + if(empty($opt)) { |
|
| 527 | + $opt='VKas'; |
|
| 528 | + } |
|
| 461 | 529 | return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
| 462 | 530 | case 'hanzen': |
| 463 | - if(empty($opt)) $opt='VKAS'; |
|
| 531 | + if(empty($opt)) { |
|
| 532 | + $opt='VKAS'; |
|
| 533 | + } |
|
| 464 | 534 | return mb_convert_kana($value,$opt,$modx->config['modx_charset']); |
| 465 | 535 | case 'str_shuffle': |
| 466 | 536 | case 'shuffle': |
@@ -485,13 +555,18 @@ discard block |
||
| 485 | 555 | $value = preg_replace('/\r/', '', $value); |
| 486 | 556 | return count(preg_split('/\n+/',$value)); |
| 487 | 557 | case 'strpos': |
| 488 | - if($opt!=0&&empty($opt)) return $value; |
|
| 558 | + if($opt!=0&&empty($opt)) { |
|
| 559 | + return $value; |
|
| 560 | + } |
|
| 489 | 561 | return $this->strpos($value,$opt); |
| 490 | 562 | case 'wordwrap': |
| 491 | 563 | // default: 70 |
| 492 | 564 | $wrapat = (int)$opt > 0 ? (int)$opt : 70; |
| 493 | - if (version_compare(PHP_VERSION, '5.3.0') >= 0) return $this->includeMdfFile('wordwrap'); |
|
| 494 | - else return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value); |
|
| 565 | + if (version_compare(PHP_VERSION, '5.3.0') >= 0) { |
|
| 566 | + return $this->includeMdfFile('wordwrap'); |
|
| 567 | + } else { |
|
| 568 | + return preg_replace("@(\b\w+\b)@e","wordwrap('\\1',\$wrapat,' ',1)",$value); |
|
| 569 | + } |
|
| 495 | 570 | case 'wrap_text': |
| 496 | 571 | $width = preg_match('/^[1-9][0-9]*$/',$opt) ? $opt : 70; |
| 497 | 572 | if($modx->config['manager_language']==='japanese-utf8') { |
@@ -507,30 +582,36 @@ discard block |
||
| 507 | 582 | $value = $this->substr($value,$width); |
| 508 | 583 | } |
| 509 | 584 | return join("\n",$chunk); |
| 585 | + } else { |
|
| 586 | + return wordwrap($value,$width,"\n",true); |
|
| 510 | 587 | } |
| 511 | - else |
|
| 512 | - return wordwrap($value,$width,"\n",true); |
|
| 513 | 588 | case 'substr': |
| 514 | - if(empty($opt)) break; |
|
| 589 | + if(empty($opt)) { |
|
| 590 | + break; |
|
| 591 | + } |
|
| 515 | 592 | if(strpos($opt,',')!==false) { |
| 516 | 593 | list($b,$e) = explode(',',$opt,2); |
| 517 | 594 | return $this->substr($value,$b,(int)$e); |
| 595 | + } else { |
|
| 596 | + return $this->substr($value,$opt); |
|
| 518 | 597 | } |
| 519 | - else return $this->substr($value,$opt); |
|
| 520 | 598 | case 'limit': |
| 521 | 599 | case 'trim_to': // http://www.movabletype.jp/documentation/appendices/modifiers/trim_to.html |
| 522 | - if(strpos($opt,'+')!==false) |
|
| 523 | - list($len,$str) = explode('+',$opt,2); |
|
| 524 | - else { |
|
| 600 | + if(strpos($opt,'+')!==false) { |
|
| 601 | + list($len,$str) = explode('+',$opt,2); |
|
| 602 | + } else { |
|
| 525 | 603 | $len = $opt; |
| 526 | 604 | $str = ''; |
| 527 | 605 | } |
| 528 | - if($len==='') $len = 100; |
|
| 529 | - if(abs($len) > $this->strlen($value)) $str =''; |
|
| 606 | + if($len==='') { |
|
| 607 | + $len = 100; |
|
| 608 | + } |
|
| 609 | + if(abs($len) > $this->strlen($value)) { |
|
| 610 | + $str =''; |
|
| 611 | + } |
|
| 530 | 612 | if(preg_match('/^[1-9][0-9]*$/',$len)) { |
| 531 | 613 | return $this->substr($value,0,$len) . $str; |
| 532 | - } |
|
| 533 | - elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) { |
|
| 614 | + } elseif(preg_match('/^\-[1-9][0-9]*$/',$len)) { |
|
| 534 | 615 | return $str . $this->substr($value,$len); |
| 535 | 616 | } |
| 536 | 617 | break; |
@@ -540,18 +621,30 @@ discard block |
||
| 540 | 621 | return $this->includeMdfFile('summary'); |
| 541 | 622 | case 'replace': |
| 542 | 623 | case 'str_replace': |
| 543 | - if(empty($opt) || strpos($opt,',')===false) break; |
|
| 544 | - if (substr_count($opt, ',') ==1) $delim = ','; |
|
| 545 | - elseif(substr_count($opt, '|') ==1) $delim = '|'; |
|
| 546 | - elseif(substr_count($opt, '=>')==1) $delim = '=>'; |
|
| 547 | - elseif(substr_count($opt, '/') ==1) $delim = '/'; |
|
| 548 | - else break; |
|
| 624 | + if(empty($opt) || strpos($opt,',')===false) { |
|
| 625 | + break; |
|
| 626 | + } |
|
| 627 | + if (substr_count($opt, ',') ==1) { |
|
| 628 | + $delim = ','; |
|
| 629 | + } elseif(substr_count($opt, '|') ==1) { |
|
| 630 | + $delim = '|'; |
|
| 631 | + } elseif(substr_count($opt, '=>')==1) { |
|
| 632 | + $delim = '=>'; |
|
| 633 | + } elseif(substr_count($opt, '/') ==1) { |
|
| 634 | + $delim = '/'; |
|
| 635 | + } else { |
|
| 636 | + break; |
|
| 637 | + } |
|
| 549 | 638 | list($s,$r) = explode($delim,$opt); |
| 550 | - if($value!=='') return str_replace($s,$r,$value); |
|
| 639 | + if($value!=='') { |
|
| 640 | + return str_replace($s,$r,$value); |
|
| 641 | + } |
|
| 551 | 642 | break; |
| 552 | 643 | case 'replace_to': |
| 553 | 644 | case 'tpl': |
| 554 | - if($value!=='') return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt); |
|
| 645 | + if($value!=='') { |
|
| 646 | + return str_replace(array('[+value+]','[+output+]','{value}','%s'),$value,$opt); |
|
| 647 | + } |
|
| 555 | 648 | break; |
| 556 | 649 | case 'eachtpl': |
| 557 | 650 | $value = explode('||',$value); |
@@ -562,59 +655,83 @@ discard block |
||
| 562 | 655 | return join("\n", $_); |
| 563 | 656 | case 'array_pop': |
| 564 | 657 | case 'array_shift': |
| 565 | - if(strpos($value,'||')!==false) $delim = '||'; |
|
| 566 | - else $delim = ','; |
|
| 658 | + if(strpos($value,'||')!==false) { |
|
| 659 | + $delim = '||'; |
|
| 660 | + } else { |
|
| 661 | + $delim = ','; |
|
| 662 | + } |
|
| 567 | 663 | return $cmd(explode($delim,$value)); |
| 568 | 664 | case 'preg_replace': |
| 569 | 665 | case 'regex_replace': |
| 570 | - if(empty($opt) || strpos($opt,',')===false) break; |
|
| 666 | + if(empty($opt) || strpos($opt,',')===false) { |
|
| 667 | + break; |
|
| 668 | + } |
|
| 571 | 669 | list($s,$r) = explode(',',$opt,2); |
| 572 | - if($value!=='') return preg_replace($s,$r,$value); |
|
| 670 | + if($value!=='') { |
|
| 671 | + return preg_replace($s,$r,$value); |
|
| 672 | + } |
|
| 573 | 673 | break; |
| 574 | 674 | case 'cat': |
| 575 | 675 | case 'concatenate': |
| 576 | 676 | case '.': |
| 577 | - if($value!=='') return $value . $opt; |
|
| 677 | + if($value!=='') { |
|
| 678 | + return $value . $opt; |
|
| 679 | + } |
|
| 578 | 680 | break; |
| 579 | 681 | case 'sprintf': |
| 580 | 682 | case 'string_format': |
| 581 | - if($value!=='') return sprintf($opt,$value); |
|
| 683 | + if($value!=='') { |
|
| 684 | + return sprintf($opt,$value); |
|
| 685 | + } |
|
| 582 | 686 | break; |
| 583 | 687 | case 'number_format': |
| 584 | - if($opt=='') $opt = 0; |
|
| 688 | + if($opt=='') { |
|
| 689 | + $opt = 0; |
|
| 690 | + } |
|
| 585 | 691 | return number_format($value,$opt); |
| 586 | 692 | case 'money_format': |
| 587 | 693 | setlocale(LC_MONETARY,setlocale(LC_TIME,0)); |
| 588 | - if($value!=='') return money_format($opt,(double)$value); |
|
| 694 | + if($value!=='') { |
|
| 695 | + return money_format($opt,(double)$value); |
|
| 696 | + } |
|
| 589 | 697 | break; |
| 590 | 698 | case 'tobool': |
| 591 | 699 | return boolval($value); |
| 592 | 700 | case 'nl2lf': |
| 593 | - if($value!=='') return str_replace(array("\r\n","\n", "\r"), '\n', $value); |
|
| 701 | + if($value!=='') { |
|
| 702 | + return str_replace(array("\r\n","\n", "\r"), '\n', $value); |
|
| 703 | + } |
|
| 594 | 704 | break; |
| 595 | 705 | case 'br2nl': |
| 596 | 706 | return preg_replace('@<br[\s/]*>@i', "\n", $value); |
| 597 | 707 | case 'nl2br': |
| 598 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) |
|
| 599 | - return nl2br($value); |
|
| 600 | - if($opt!=='') |
|
| 601 | - { |
|
| 708 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
| 709 | + return nl2br($value); |
|
| 710 | + } |
|
| 711 | + if($opt!=='') { |
|
| 602 | 712 | $opt = trim($opt); |
| 603 | 713 | $opt = strtolower($opt); |
| 604 | - if($opt==='false') $opt = false; |
|
| 605 | - elseif($opt==='0') $opt = false; |
|
| 606 | - else $opt = true; |
|
| 714 | + if($opt==='false') { |
|
| 715 | + $opt = false; |
|
| 716 | + } elseif($opt==='0') { |
|
| 717 | + $opt = false; |
|
| 718 | + } else { |
|
| 719 | + $opt = true; |
|
| 720 | + } |
|
| 721 | + } elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html') { |
|
| 722 | + $opt = false; |
|
| 723 | + } else { |
|
| 724 | + $opt = true; |
|
| 607 | 725 | } |
| 608 | - elseif(isset($modx->config['mce_element_format'])&&$modx->config['mce_element_format']==='html') |
|
| 609 | - $opt = false; |
|
| 610 | - else $opt = true; |
|
| 611 | 726 | return nl2br($value,$opt); |
| 612 | 727 | case 'ltrim': |
| 613 | 728 | case 'rtrim': |
| 614 | 729 | case 'trim': // ref http://mblo.info/modifiers/custom-modifiers/rtrim_opt.html |
| 615 | - if($opt==='') |
|
| 616 | - return $cmd($value); |
|
| 617 | - else return $cmd($value,$opt); |
|
| 730 | + if($opt==='') { |
|
| 731 | + return $cmd($value); |
|
| 732 | + } else { |
|
| 733 | + return $cmd($value,$opt); |
|
| 734 | + } |
|
| 618 | 735 | // These are all straight wrappers for PHP functions |
| 619 | 736 | case 'ucfirst': |
| 620 | 737 | case 'lcfirst': |
@@ -625,15 +742,24 @@ discard block |
||
| 625 | 742 | case 'strftime': |
| 626 | 743 | case 'date': |
| 627 | 744 | case 'dateformat': |
| 628 | - if(empty($opt)) $opt = $modx->toDateFormat(null, 'formatOnly'); |
|
| 629 | - if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
|
| 630 | - if(strpos($opt,'%')!==false) |
|
| 631 | - return strftime($opt,0+$value); |
|
| 632 | - else |
|
| 633 | - return date($opt,0+$value); |
|
| 745 | + if(empty($opt)) { |
|
| 746 | + $opt = $modx->toDateFormat(null, 'formatOnly'); |
|
| 747 | + } |
|
| 748 | + if(!preg_match('@^[0-9]+$@',$value)) { |
|
| 749 | + $value = strtotime($value); |
|
| 750 | + } |
|
| 751 | + if(strpos($opt,'%')!==false) { |
|
| 752 | + return strftime($opt,0+$value); |
|
| 753 | + } else { |
|
| 754 | + return date($opt,0+$value); |
|
| 755 | + } |
|
| 634 | 756 | case 'time': |
| 635 | - if(empty($opt)) $opt = '%H:%M'; |
|
| 636 | - if(!preg_match('@^[0-9]+$@',$value)) $value = strtotime($value); |
|
| 757 | + if(empty($opt)) { |
|
| 758 | + $opt = '%H:%M'; |
|
| 759 | + } |
|
| 760 | + if(!preg_match('@^[0-9]+$@',$value)) { |
|
| 761 | + $value = strtotime($value); |
|
| 762 | + } |
|
| 637 | 763 | return strftime($opt,0+$value); |
| 638 | 764 | case 'strtotime': |
| 639 | 765 | return strtotime($value); |
@@ -643,7 +769,9 @@ discard block |
||
| 643 | 769 | case 'tofloat': |
| 644 | 770 | return floatval($value); |
| 645 | 771 | case 'round': |
| 646 | - if(!$opt) $opt = 0; |
|
| 772 | + if(!$opt) { |
|
| 773 | + $opt = 0; |
|
| 774 | + } |
|
| 647 | 775 | return $cmd($value,$opt); |
| 648 | 776 | case 'max': |
| 649 | 777 | case 'min': |
@@ -655,28 +783,42 @@ discard block |
||
| 655 | 783 | case 'math': |
| 656 | 784 | case 'calc': |
| 657 | 785 | $value = (int)$value; |
| 658 | - if(empty($value)) $value = '0'; |
|
| 786 | + if(empty($value)) { |
|
| 787 | + $value = '0'; |
|
| 788 | + } |
|
| 659 | 789 | $filter = str_replace(array('[+value+]','[+output+]','{value}','%s'),'?',$opt); |
| 660 | 790 | $filter = preg_replace('@([a-zA-Z\n\r\t\s])@','',$filter); |
| 661 | - if(strpos($filter,'?')===false) $filter = "?{$filter}"; |
|
| 791 | + if(strpos($filter,'?')===false) { |
|
| 792 | + $filter = "?{$filter}"; |
|
| 793 | + } |
|
| 662 | 794 | $filter = str_replace('?',$value,$filter); |
| 663 | 795 | return eval("return {$filter};"); |
| 664 | 796 | case 'count': |
| 665 | - if($value=='') return 0; |
|
| 797 | + if($value=='') { |
|
| 798 | + return 0; |
|
| 799 | + } |
|
| 666 | 800 | $value = explode(',',$value); |
| 667 | 801 | return count($value); |
| 668 | 802 | case 'sort': |
| 669 | 803 | case 'rsort': |
| 670 | - if(strpos($value,"\n")!==false) $delim="\n"; |
|
| 671 | - else $delim = ','; |
|
| 804 | + if(strpos($value,"\n")!==false) { |
|
| 805 | + $delim="\n"; |
|
| 806 | + } else { |
|
| 807 | + $delim = ','; |
|
| 808 | + } |
|
| 672 | 809 | $swap = explode($delim,$value); |
| 673 | - if(!$opt) $opt = SORT_REGULAR; |
|
| 674 | - else $opt = constant($opt); |
|
| 810 | + if(!$opt) { |
|
| 811 | + $opt = SORT_REGULAR; |
|
| 812 | + } else { |
|
| 813 | + $opt = constant($opt); |
|
| 814 | + } |
|
| 675 | 815 | $cmd($swap,$opt); |
| 676 | 816 | return join($delim,$swap); |
| 677 | 817 | ##### Resource fields |
| 678 | 818 | case 'id': |
| 679 | - if($opt) return $this->getDocumentObject($opt,$key); |
|
| 819 | + if($opt) { |
|
| 820 | + return $this->getDocumentObject($opt,$key); |
|
| 821 | + } |
|
| 680 | 822 | break; |
| 681 | 823 | case 'type': |
| 682 | 824 | case 'contenttype': |
@@ -713,7 +855,9 @@ discard block |
||
| 713 | 855 | case 'privatemgr': |
| 714 | 856 | case 'content_dispo': |
| 715 | 857 | case 'hidemenu': |
| 716 | - if($cmd==='contenttype') $cmd = 'contentType'; |
|
| 858 | + if($cmd==='contenttype') { |
|
| 859 | + $cmd = 'contentType'; |
|
| 860 | + } |
|
| 717 | 861 | return $this->getDocumentObject($value,$cmd); |
| 718 | 862 | case 'title': |
| 719 | 863 | $pagetitle = $this->getDocumentObject($value,'pagetitle'); |
@@ -728,13 +872,20 @@ discard block |
||
| 728 | 872 | $templateName = $modx->db->getValue($rs); |
| 729 | 873 | return !$templateName ? '(blank)' : $templateName; |
| 730 | 874 | case 'getfield': |
| 731 | - if(!$opt) $opt = 'content'; |
|
| 875 | + if(!$opt) { |
|
| 876 | + $opt = 'content'; |
|
| 877 | + } |
|
| 732 | 878 | return $modx->getField($opt,$value); |
| 733 | 879 | case 'children': |
| 734 | 880 | case 'childids': |
| 735 | - if($value=='') $value = 0; // 値がない場合はルートと見なす |
|
| 881 | + if($value=='') { |
|
| 882 | + $value = 0; |
|
| 883 | + } |
|
| 884 | + // 値がない場合はルートと見なす |
|
| 736 | 885 | $published = 1; |
| 737 | - if($opt=='') $opt = 'page'; |
|
| 886 | + if($opt=='') { |
|
| 887 | + $opt = 'page'; |
|
| 888 | + } |
|
| 738 | 889 | $_ = explode(',',$opt); |
| 739 | 890 | $where = array(); |
| 740 | 891 | foreach($_ as $opt) { |
@@ -750,29 +901,43 @@ discard block |
||
| 750 | 901 | $where = join(' AND ', $where); |
| 751 | 902 | $children = $modx->getDocumentChildren($value, $published, '0', 'id', $where); |
| 752 | 903 | $result = array(); |
| 753 | - foreach((array)$children as $child){ |
|
| 904 | + foreach((array)$children as $child) { |
|
| 754 | 905 | $result[] = $child['id']; |
| 755 | 906 | } |
| 756 | 907 | return join(',', $result); |
| 757 | 908 | case 'fullurl': |
| 758 | - if(!is_numeric($value)) return $value; |
|
| 909 | + if(!is_numeric($value)) { |
|
| 910 | + return $value; |
|
| 911 | + } |
|
| 759 | 912 | return $modx->makeUrl($value); |
| 760 | 913 | case 'makeurl': |
| 761 | - if(!is_numeric($value)) return $value; |
|
| 762 | - if(!$opt) $opt = 'full'; |
|
| 914 | + if(!is_numeric($value)) { |
|
| 915 | + return $value; |
|
| 916 | + } |
|
| 917 | + if(!$opt) { |
|
| 918 | + $opt = 'full'; |
|
| 919 | + } |
|
| 763 | 920 | return $modx->makeUrl($value,'','',$opt); |
| 764 | 921 | |
| 765 | 922 | ##### File system |
| 766 | 923 | case 'getimageinfo': |
| 767 | 924 | case 'imageinfo': |
| 768 | - if(!is_file($value)) return ''; |
|
| 925 | + if(!is_file($value)) { |
|
| 926 | + return ''; |
|
| 927 | + } |
|
| 769 | 928 | $_ = getimagesize($value); |
| 770 | - if(!$_[0]) return ''; |
|
| 929 | + if(!$_[0]) { |
|
| 930 | + return ''; |
|
| 931 | + } |
|
| 771 | 932 | $info['width'] = $_[0]; |
| 772 | 933 | $info['height'] = $_[1]; |
| 773 | - if ($_[0] > $_[1]) $info['aspect'] = 'landscape'; |
|
| 774 | - elseif($_[0] < $_[1]) $info['aspect'] = 'portrait'; |
|
| 775 | - else $info['aspect'] = 'square'; |
|
| 934 | + if ($_[0] > $_[1]) { |
|
| 935 | + $info['aspect'] = 'landscape'; |
|
| 936 | + } elseif($_[0] < $_[1]) { |
|
| 937 | + $info['aspect'] = 'portrait'; |
|
| 938 | + } else { |
|
| 939 | + $info['aspect'] = 'square'; |
|
| 940 | + } |
|
| 776 | 941 | switch($_[2]) { |
| 777 | 942 | case IMAGETYPE_GIF : $info['type'] = 'gif'; break; |
| 778 | 943 | case IMAGETYPE_JPEG : $info['type'] = 'jpg'; break; |
@@ -791,33 +956,47 @@ discard block |
||
| 791 | 956 | |
| 792 | 957 | case 'file_get_contents': |
| 793 | 958 | case 'readfile': |
| 794 | - if(!is_file($value)) return $value; |
|
| 959 | + if(!is_file($value)) { |
|
| 960 | + return $value; |
|
| 961 | + } |
|
| 795 | 962 | $value = realpath($value); |
| 796 | - if(strpos($value,MODX_MANAGER_PATH)!==false) exit('Can not read core file'); |
|
| 963 | + if(strpos($value,MODX_MANAGER_PATH)!==false) { |
|
| 964 | + exit('Can not read core file'); |
|
| 965 | + } |
|
| 797 | 966 | $ext = strtolower(substr($value,-4)); |
| 798 | - if($ext==='.php') exit('Can not read php file'); |
|
| 799 | - if($ext==='.cgi') exit('Can not read cgi file'); |
|
| 967 | + if($ext==='.php') { |
|
| 968 | + exit('Can not read php file'); |
|
| 969 | + } |
|
| 970 | + if($ext==='.cgi') { |
|
| 971 | + exit('Can not read cgi file'); |
|
| 972 | + } |
|
| 800 | 973 | return file_get_contents($value); |
| 801 | 974 | case 'filesize': |
| 802 | - if($value == '') return ''; |
|
| 975 | + if($value == '') { |
|
| 976 | + return ''; |
|
| 977 | + } |
|
| 803 | 978 | $filename = $value; |
| 804 | 979 | |
| 805 | 980 | $site_url = $modx->config['site_url']; |
| 806 | - if(strpos($filename,$site_url) === 0) |
|
| 807 | - $filename = substr($filename,0,strlen($site_url)); |
|
| 981 | + if(strpos($filename,$site_url) === 0) { |
|
| 982 | + $filename = substr($filename,0,strlen($site_url)); |
|
| 983 | + } |
|
| 808 | 984 | $filename = trim($filename,'/'); |
| 809 | 985 | |
| 810 | 986 | $opt = trim($opt,'/'); |
| 811 | - if($opt!=='') $opt .= '/'; |
|
| 987 | + if($opt!=='') { |
|
| 988 | + $opt .= '/'; |
|
| 989 | + } |
|
| 812 | 990 | |
| 813 | 991 | $filename = MODX_BASE_PATH.$opt.$filename; |
| 814 | 992 | |
| 815 | - if(is_file($filename)){ |
|
| 993 | + if(is_file($filename)) { |
|
| 816 | 994 | clearstatcache(); |
| 817 | 995 | $size = filesize($filename); |
| 818 | 996 | return $size; |
| 997 | + } else { |
|
| 998 | + return ''; |
|
| 819 | 999 | } |
| 820 | - else return ''; |
|
| 821 | 1000 | ##### User info |
| 822 | 1001 | case 'username': |
| 823 | 1002 | case 'fullname': |
@@ -845,32 +1024,47 @@ discard block |
||
| 845 | 1024 | $this->opt = $cmd; |
| 846 | 1025 | return $this->includeMdfFile('moduser'); |
| 847 | 1026 | case 'userinfo': |
| 848 | - if(empty($opt)) $this->opt = 'username'; |
|
| 1027 | + if(empty($opt)) { |
|
| 1028 | + $this->opt = 'username'; |
|
| 1029 | + } |
|
| 849 | 1030 | return $this->includeMdfFile('moduser'); |
| 850 | 1031 | case 'webuserinfo': |
| 851 | - if(empty($opt)) $this->opt = 'username'; |
|
| 1032 | + if(empty($opt)) { |
|
| 1033 | + $this->opt = 'username'; |
|
| 1034 | + } |
|
| 852 | 1035 | $this->value = -$value; |
| 853 | 1036 | return $this->includeMdfFile('moduser'); |
| 854 | 1037 | ##### Special functions |
| 855 | 1038 | case 'ifempty': |
| 856 | 1039 | case '_default': |
| 857 | 1040 | case 'default': |
| 858 | - if (empty($value)) return $opt; break; |
|
| 1041 | + if (empty($value)) { |
|
| 1042 | + return $opt; |
|
| 1043 | + } |
|
| 1044 | + break; |
|
| 859 | 1045 | case 'ifnotempty': |
| 860 | - if (!empty($value)) return $opt; break; |
|
| 1046 | + if (!empty($value)) { |
|
| 1047 | + return $opt; |
|
| 1048 | + } |
|
| 1049 | + break; |
|
| 861 | 1050 | case 'datagrid': |
| 862 | 1051 | include_once(MODX_CORE_PATH . 'controls/datagrid.class.php'); |
| 863 | 1052 | $grd = new DataGrid(null, trim($value)); |
| 864 | 1053 | $grd->itemStyle = ''; |
| 865 | 1054 | $grd->altItemStyle = ''; |
| 866 | 1055 | $pos = strpos($value,"\n"); |
| 867 | - if($pos) $_ = substr($value,0,$pos); |
|
| 868 | - else $_ = $pos; |
|
| 1056 | + if($pos) { |
|
| 1057 | + $_ = substr($value,0,$pos); |
|
| 1058 | + } else { |
|
| 1059 | + $_ = $pos; |
|
| 1060 | + } |
|
| 869 | 1061 | $grd->cdelim = strpos($_,"\t")!==false ? 'tab' : ','; |
| 870 | 1062 | return $grd->render(); |
| 871 | 1063 | case 'rotate': |
| 872 | 1064 | case 'evenodd': |
| 873 | - if(strpos($opt,',')===false) $opt = 'odd,even'; |
|
| 1065 | + if(strpos($opt,',')===false) { |
|
| 1066 | + $opt = 'odd,even'; |
|
| 1067 | + } |
|
| 874 | 1068 | $_ = explode(',', $opt); |
| 875 | 1069 | $c = count($_); |
| 876 | 1070 | $i = $value + $c; |
@@ -879,7 +1073,9 @@ discard block |
||
| 879 | 1073 | case 'takeval': |
| 880 | 1074 | $arr = explode(",",$opt); |
| 881 | 1075 | $idx = $value; |
| 882 | - if(!is_numeric($idx)) return $value; |
|
| 1076 | + if(!is_numeric($idx)) { |
|
| 1077 | + return $value; |
|
| 1078 | + } |
|
| 883 | 1079 | return $arr[$idx]; |
| 884 | 1080 | case 'getimage': |
| 885 | 1081 | return $this->includeMdfFile('getimage'); |
@@ -887,14 +1083,18 @@ discard block |
||
| 887 | 1083 | return $modx->nicesize($value); |
| 888 | 1084 | case 'googlemap': |
| 889 | 1085 | case 'googlemaps': |
| 890 | - if(empty($opt)) $opt = 'border:none;width:500px;height:350px;'; |
|
| 1086 | + if(empty($opt)) { |
|
| 1087 | + $opt = 'border:none;width:500px;height:350px;'; |
|
| 1088 | + } |
|
| 891 | 1089 | $tpl = '<iframe style="[+style+]" src="https://maps.google.co.jp/maps?ll=[+value+]&output=embed&z=15"></iframe>'; |
| 892 | 1090 | $ph['style'] = $opt; |
| 893 | 1091 | $ph['value'] = $value; |
| 894 | 1092 | return $modx->parseText($tpl,$ph); |
| 895 | 1093 | case 'youtube': |
| 896 | 1094 | case 'youtube16x9': |
| 897 | - if(empty($opt)) $opt = 560; |
|
| 1095 | + if(empty($opt)) { |
|
| 1096 | + $opt = 560; |
|
| 1097 | + } |
|
| 898 | 1098 | $h = round($opt*0.5625); |
| 899 | 1099 | $tpl = '<iframe width="%s" height="%s" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>'; |
| 900 | 1100 | return sprintf($tpl,$opt,$h,$value); |
@@ -927,7 +1127,8 @@ discard block |
||
| 927 | 1127 | return $value; |
| 928 | 1128 | } |
| 929 | 1129 | |
| 930 | - public function includeMdfFile($cmd) { |
|
| 1130 | + public function includeMdfFile($cmd) |
|
| 1131 | + { |
|
| 931 | 1132 | global $modx; |
| 932 | 1133 | $key = $this->key; |
| 933 | 1134 | $value = $this->value; |
@@ -938,55 +1139,65 @@ discard block |
||
| 938 | 1139 | public function getValueFromElement($key, $value, $cmd, $opt) |
| 939 | 1140 | { |
| 940 | 1141 | global $modx; |
| 941 | - if( isset($modx->snippetCache[$this->elmName]) ) |
|
| 942 | - { |
|
| 1142 | + if( isset($modx->snippetCache[$this->elmName]) ) { |
|
| 943 | 1143 | $php = $modx->snippetCache[$this->elmName]; |
| 944 | - } |
|
| 945 | - else |
|
| 946 | - { |
|
| 1144 | + } else { |
|
| 947 | 1145 | $esc_elmName = $modx->db->escape($this->elmName); |
| 948 | 1146 | $result = $modx->db->select('snippet','[+prefix+]site_snippets',"name='{$esc_elmName}'"); |
| 949 | 1147 | $total = $modx->db->getRecordCount($result); |
| 950 | - if($total == 1) |
|
| 951 | - { |
|
| 1148 | + if($total == 1) { |
|
| 952 | 1149 | $row = $modx->db->getRow($result); |
| 953 | 1150 | $php = $row['snippet']; |
| 954 | - } |
|
| 955 | - elseif($total == 0) |
|
| 956 | - { |
|
| 1151 | + } elseif($total == 0) { |
|
| 957 | 1152 | $assets_path = MODX_BASE_PATH.'assets/'; |
| 958 | - if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) |
|
| 959 | - $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php"; |
|
| 960 | - elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) |
|
| 961 | - $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php"; |
|
| 962 | - elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) |
|
| 963 | - $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"; |
|
| 964 | - else $modifiers_path = false; |
|
| 1153 | + if(is_file($assets_path."modifiers/mdf_{$cmd}.inc.php")) { |
|
| 1154 | + $modifiers_path = $assets_path."modifiers/mdf_{$cmd}.inc.php"; |
|
| 1155 | + } elseif(is_file($assets_path."plugins/phx/modifiers/{$cmd}.phx.php")) { |
|
| 1156 | + $modifiers_path = $assets_path."plugins/phx/modifiers/{$cmd}.phx.php"; |
|
| 1157 | + } elseif(is_file(MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php")) { |
|
| 1158 | + $modifiers_path = MODX_CORE_PATH."extenders/modifiers/mdf_{$cmd}.inc.php"; |
|
| 1159 | + } else { |
|
| 1160 | + $modifiers_path = false; |
|
| 1161 | + } |
|
| 965 | 1162 | |
| 966 | 1163 | if($modifiers_path !== false) { |
| 967 | 1164 | $php = @file_get_contents($modifiers_path); |
| 968 | 1165 | $php = trim($php); |
| 969 | - if(substr($php,0,5)==='<?php') $php = substr($php,6); |
|
| 970 | - if(substr($php,0,2)==='<?') $php = substr($php,3); |
|
| 971 | - if(substr($php,-2)==='?>') $php = substr($php,0,-2); |
|
| 972 | - if($this->elmName!=='') |
|
| 973 | - $modx->snippetCache[$this->elmName.'Props'] = ''; |
|
| 974 | - } |
|
| 975 | - else |
|
| 976 | - $php = false; |
|
| 1166 | + if(substr($php,0,5)==='<?php') { |
|
| 1167 | + $php = substr($php,6); |
|
| 1168 | + } |
|
| 1169 | + if(substr($php,0,2)==='<?') { |
|
| 1170 | + $php = substr($php,3); |
|
| 1171 | + } |
|
| 1172 | + if(substr($php,-2)==='?>') { |
|
| 1173 | + $php = substr($php,0,-2); |
|
| 1174 | + } |
|
| 1175 | + if($this->elmName!=='') { |
|
| 1176 | + $modx->snippetCache[$this->elmName.'Props'] = ''; |
|
| 1177 | + } |
|
| 1178 | + } else { |
|
| 1179 | + $php = false; |
|
| 1180 | + } |
|
| 1181 | + } else { |
|
| 1182 | + $php = false; |
|
| 1183 | + } |
|
| 1184 | + if($this->elmName!=='') { |
|
| 1185 | + $modx->snippetCache[$this->elmName]= $php; |
|
| 977 | 1186 | } |
| 978 | - else $php = false; |
|
| 979 | - if($this->elmName!=='') $modx->snippetCache[$this->elmName]= $php; |
|
| 980 | 1187 | } |
| 981 | - if($php==='') $php=false; |
|
| 1188 | + if($php==='') { |
|
| 1189 | + $php=false; |
|
| 1190 | + } |
|
| 982 | 1191 | |
| 983 | - if($php===false) $html = $modx->getChunk($this->elmName); |
|
| 984 | - else $html = false; |
|
| 1192 | + if($php===false) { |
|
| 1193 | + $html = $modx->getChunk($this->elmName); |
|
| 1194 | + } else { |
|
| 1195 | + $html = false; |
|
| 1196 | + } |
|
| 985 | 1197 | |
| 986 | 1198 | $self = '[+output+]'; |
| 987 | 1199 | |
| 988 | - if($php !== false) |
|
| 989 | - { |
|
| 1200 | + if($php !== false) { |
|
| 990 | 1201 | ob_start(); |
| 991 | 1202 | $options = $opt; |
| 992 | 1203 | $output = $value; |
@@ -998,19 +1209,19 @@ discard block |
||
| 998 | 1209 | $this->vars['options'] = & $opt; |
| 999 | 1210 | $custom = eval($php); |
| 1000 | 1211 | $msg = ob_get_contents(); |
| 1001 | - if($value===$this->bt) $value = $msg . $custom; |
|
| 1212 | + if($value===$this->bt) { |
|
| 1213 | + $value = $msg . $custom; |
|
| 1214 | + } |
|
| 1002 | 1215 | ob_end_clean(); |
| 1003 | - } |
|
| 1004 | - elseif($html!==false && isset($value) && $value!=='') |
|
| 1005 | - { |
|
| 1216 | + } elseif($html!==false && isset($value) && $value!=='') { |
|
| 1006 | 1217 | $html = str_replace(array($self,'[+value+]'), $value, $html); |
| 1007 | 1218 | $value = str_replace(array('[+options+]','[+param+]'), $opt, $html); |
| 1219 | + } else { |
|
| 1220 | + return false; |
|
| 1008 | 1221 | } |
| 1009 | - else return false; |
|
| 1010 | 1222 | |
| 1011 | 1223 | if($php===false && $html===false && $value!=='' |
| 1012 | - && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false)) |
|
| 1013 | - { |
|
| 1224 | + && (strpos($cmd,'[+value+]')!==false || strpos($cmd,$self)!==false)) { |
|
| 1014 | 1225 | $value = str_replace(array('[+value+]',$self),$value,$cmd); |
| 1015 | 1226 | } |
| 1016 | 1227 | return $value; |
@@ -1020,23 +1231,39 @@ discard block |
||
| 1020 | 1231 | { |
| 1021 | 1232 | global $modx; |
| 1022 | 1233 | |
| 1023 | - if(strpos($content,'[')===false && strpos($content,'{')===false) return $content; |
|
| 1234 | + if(strpos($content,'[')===false && strpos($content,'{')===false) { |
|
| 1235 | + return $content; |
|
| 1236 | + } |
|
| 1024 | 1237 | |
| 1025 | - if(!$modx->maxParserPasses) $modx->maxParserPasses = 10; |
|
| 1238 | + if(!$modx->maxParserPasses) { |
|
| 1239 | + $modx->maxParserPasses = 10; |
|
| 1240 | + } |
|
| 1026 | 1241 | $bt=''; |
| 1027 | 1242 | $i=0; |
| 1028 | - while($bt!==$content) |
|
| 1029 | - { |
|
| 1243 | + while($bt!==$content) { |
|
| 1030 | 1244 | $bt = $content; |
| 1031 | - if(strpos($content,'[*')!==false && $modx->documentIdentifier) |
|
| 1032 | - $content = $modx->mergeDocumentContent($content); |
|
| 1033 | - if(strpos($content,'[(')!==false) $content = $modx->mergeSettingsContent($content); |
|
| 1034 | - if(strpos($content,'{{')!==false) $content = $modx->mergeChunkContent($content); |
|
| 1035 | - if(strpos($content,'[!')!==false) $content = str_replace(array('[!','!]'),array('[[',']]'),$content); |
|
| 1036 | - if(strpos($content,'[[')!==false) $content = $modx->evalSnippets($content); |
|
| 1037 | - |
|
| 1038 | - if($content===$bt) break; |
|
| 1039 | - if($modx->maxParserPasses < $i) break; |
|
| 1245 | + if(strpos($content,'[*')!==false && $modx->documentIdentifier) { |
|
| 1246 | + $content = $modx->mergeDocumentContent($content); |
|
| 1247 | + } |
|
| 1248 | + if(strpos($content,'[(')!==false) { |
|
| 1249 | + $content = $modx->mergeSettingsContent($content); |
|
| 1250 | + } |
|
| 1251 | + if(strpos($content,'{{')!==false) { |
|
| 1252 | + $content = $modx->mergeChunkContent($content); |
|
| 1253 | + } |
|
| 1254 | + if(strpos($content,'[!')!==false) { |
|
| 1255 | + $content = str_replace(array('[!','!]'),array('[[',']]'),$content); |
|
| 1256 | + } |
|
| 1257 | + if(strpos($content,'[[')!==false) { |
|
| 1258 | + $content = $modx->evalSnippets($content); |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + if($content===$bt) { |
|
| 1262 | + break; |
|
| 1263 | + } |
|
| 1264 | + if($modx->maxParserPasses < $i) { |
|
| 1265 | + break; |
|
| 1266 | + } |
|
| 1040 | 1267 | $i++; |
| 1041 | 1268 | } |
| 1042 | 1269 | return $content; |
@@ -1047,103 +1274,138 @@ discard block |
||
| 1047 | 1274 | global $modx; |
| 1048 | 1275 | |
| 1049 | 1276 | $target = trim($target); |
| 1050 | - if(empty($target)) $target = $modx->config['site_start']; |
|
| 1051 | - if(preg_match('@^[1-9][0-9]*$@',$target)) $method='id'; |
|
| 1052 | - else $method = 'alias'; |
|
| 1277 | + if(empty($target)) { |
|
| 1278 | + $target = $modx->config['site_start']; |
|
| 1279 | + } |
|
| 1280 | + if(preg_match('@^[1-9][0-9]*$@',$target)) { |
|
| 1281 | + $method='id'; |
|
| 1282 | + } else { |
|
| 1283 | + $method = 'alias'; |
|
| 1284 | + } |
|
| 1053 | 1285 | |
| 1054 | - if(!isset($this->documentObject[$target])) |
|
| 1055 | - { |
|
| 1286 | + if(!isset($this->documentObject[$target])) { |
|
| 1056 | 1287 | $this->documentObject[$target] = $modx->getDocumentObject($method,$target,'direct'); |
| 1057 | 1288 | } |
| 1058 | 1289 | |
| 1059 | - if($this->documentObject[$target]['publishedon']==='0') |
|
| 1060 | - return ''; |
|
| 1061 | - elseif(isset($this->documentObject[$target][$field])) |
|
| 1062 | - { |
|
| 1063 | - if(is_array($this->documentObject[$target][$field])) |
|
| 1064 | - { |
|
| 1290 | + if($this->documentObject[$target]['publishedon']==='0') { |
|
| 1291 | + return ''; |
|
| 1292 | + } elseif(isset($this->documentObject[$target][$field])) { |
|
| 1293 | + if(is_array($this->documentObject[$target][$field])) { |
|
| 1065 | 1294 | $a = $modx->getTemplateVarOutput($field,$target); |
| 1066 | 1295 | $this->documentObject[$target][$field] = $a[$field]; |
| 1067 | 1296 | } |
| 1297 | + } else { |
|
| 1298 | + $this->documentObject[$target][$field] = false; |
|
| 1068 | 1299 | } |
| 1069 | - else $this->documentObject[$target][$field] = false; |
|
| 1070 | 1300 | |
| 1071 | 1301 | return $this->documentObject[$target][$field]; |
| 1072 | 1302 | } |
| 1073 | 1303 | |
| 1074 | - public function setPlaceholders($value = '', $key = '', $path = '') { |
|
| 1075 | - if($path!=='') $key = "{$path}.{$key}"; |
|
| 1304 | + public function setPlaceholders($value = '', $key = '', $path = '') |
|
| 1305 | + { |
|
| 1306 | + if($path!=='') { |
|
| 1307 | + $key = "{$path}.{$key}"; |
|
| 1308 | + } |
|
| 1076 | 1309 | if (is_array($value)) { |
| 1077 | 1310 | foreach ($value as $subkey => $subval) { |
| 1078 | 1311 | $this->setPlaceholders($subval, $subkey, $key); |
| 1079 | 1312 | } |
| 1313 | + } else { |
|
| 1314 | + $this->setModifiersVariable($key, $value); |
|
| 1080 | 1315 | } |
| 1081 | - else $this->setModifiersVariable($key, $value); |
|
| 1082 | 1316 | } |
| 1083 | 1317 | |
| 1084 | 1318 | // Sets a placeholder variable which can only be access by Modifiers |
| 1085 | - public function setModifiersVariable($key, $value) { |
|
| 1086 | - if ($key != 'phx' && $key != 'dummy') $this->placeholders[$key] = $value; |
|
| 1319 | + public function setModifiersVariable($key, $value) |
|
| 1320 | + { |
|
| 1321 | + if ($key != 'phx' && $key != 'dummy') { |
|
| 1322 | + $this->placeholders[$key] = $value; |
|
| 1323 | + } |
|
| 1087 | 1324 | } |
| 1088 | 1325 | |
| 1089 | 1326 | //mbstring |
| 1090 | - public function substr($str, $s, $l = null) { |
|
| 1327 | + public function substr($str, $s, $l = null) |
|
| 1328 | + { |
|
| 1091 | 1329 | global $modx; |
| 1092 | - if(is_null($l)) $l = $this->strlen($str); |
|
| 1093 | - if (function_exists('mb_substr')) |
|
| 1094 | - { |
|
| 1095 | - if(strpos($str,"\r")!==false) |
|
| 1096 | - $str = str_replace(array("\r\n","\r"), "\n", $str); |
|
| 1330 | + if(is_null($l)) { |
|
| 1331 | + $l = $this->strlen($str); |
|
| 1332 | + } |
|
| 1333 | + if (function_exists('mb_substr')) { |
|
| 1334 | + if(strpos($str,"\r")!==false) { |
|
| 1335 | + $str = str_replace(array("\r\n","\r"), "\n", $str); |
|
| 1336 | + } |
|
| 1097 | 1337 | return mb_substr($str, $s, $l, $modx->config['modx_charset']); |
| 1098 | 1338 | } |
| 1099 | 1339 | return substr($str, $s, $l); |
| 1100 | 1340 | } |
| 1101 | - public function strpos($haystack,$needle,$offset=0) { |
|
| 1341 | + public function strpos($haystack,$needle,$offset=0) |
|
| 1342 | + { |
|
| 1102 | 1343 | global $modx; |
| 1103 | - if (function_exists('mb_strpos')) return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']); |
|
| 1344 | + if (function_exists('mb_strpos')) { |
|
| 1345 | + return mb_strpos($haystack,$needle,$offset,$modx->config['modx_charset']); |
|
| 1346 | + } |
|
| 1104 | 1347 | return strpos($haystack,$needle,$offset); |
| 1105 | 1348 | } |
| 1106 | - public function strlen($str) { |
|
| 1349 | + public function strlen($str) |
|
| 1350 | + { |
|
| 1107 | 1351 | global $modx; |
| 1108 | - if (function_exists('mb_strlen')) return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']); |
|
| 1352 | + if (function_exists('mb_strlen')) { |
|
| 1353 | + return mb_strlen(str_replace("\r\n", "\n", $str),$modx->config['modx_charset']); |
|
| 1354 | + } |
|
| 1109 | 1355 | return strlen($str); |
| 1110 | 1356 | } |
| 1111 | - public function strtolower($str) { |
|
| 1112 | - if (function_exists('mb_strtolower')) return mb_strtolower($str); |
|
| 1357 | + public function strtolower($str) |
|
| 1358 | + { |
|
| 1359 | + if (function_exists('mb_strtolower')) { |
|
| 1360 | + return mb_strtolower($str); |
|
| 1361 | + } |
|
| 1113 | 1362 | return strtolower($str); |
| 1114 | 1363 | } |
| 1115 | - public function strtoupper($str) { |
|
| 1116 | - if (function_exists('mb_strtoupper')) return mb_strtoupper($str); |
|
| 1364 | + public function strtoupper($str) |
|
| 1365 | + { |
|
| 1366 | + if (function_exists('mb_strtoupper')) { |
|
| 1367 | + return mb_strtoupper($str); |
|
| 1368 | + } |
|
| 1117 | 1369 | return strtoupper($str); |
| 1118 | 1370 | } |
| 1119 | - public function ucfirst($str) { |
|
| 1120 | - if (function_exists('mb_strtoupper')) |
|
| 1121 | - return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
|
| 1371 | + public function ucfirst($str) |
|
| 1372 | + { |
|
| 1373 | + if (function_exists('mb_strtoupper')) { |
|
| 1374 | + return mb_strtoupper($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
|
| 1375 | + } |
|
| 1122 | 1376 | return ucfirst($str); |
| 1123 | 1377 | } |
| 1124 | - public function lcfirst($str) { |
|
| 1125 | - if (function_exists('mb_strtolower')) |
|
| 1126 | - return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
|
| 1378 | + public function lcfirst($str) |
|
| 1379 | + { |
|
| 1380 | + if (function_exists('mb_strtolower')) { |
|
| 1381 | + return mb_strtolower($this->substr($str, 0, 1)).$this->substr($str, 1, $this->strlen($str)); |
|
| 1382 | + } |
|
| 1127 | 1383 | return lcfirst($str); |
| 1128 | 1384 | } |
| 1129 | - public function ucwords($str) { |
|
| 1130 | - if (function_exists('mb_convert_case')) |
|
| 1131 | - return mb_convert_case($str, MB_CASE_TITLE); |
|
| 1385 | + public function ucwords($str) |
|
| 1386 | + { |
|
| 1387 | + if (function_exists('mb_convert_case')) { |
|
| 1388 | + return mb_convert_case($str, MB_CASE_TITLE); |
|
| 1389 | + } |
|
| 1132 | 1390 | return ucwords($str); |
| 1133 | 1391 | } |
| 1134 | - public function strrev($str) { |
|
| 1392 | + public function strrev($str) |
|
| 1393 | + { |
|
| 1135 | 1394 | preg_match_all('/./us', $str, $ar); |
| 1136 | 1395 | return join(array_reverse($ar[0])); |
| 1137 | 1396 | } |
| 1138 | - public function str_shuffle($str) { |
|
| 1397 | + public function str_shuffle($str) |
|
| 1398 | + { |
|
| 1139 | 1399 | preg_match_all('/./us', $str, $ar); |
| 1140 | 1400 | shuffle($ar[0]); |
| 1141 | 1401 | return join($ar[0]); |
| 1142 | 1402 | } |
| 1143 | - public function str_word_count($str) { |
|
| 1403 | + public function str_word_count($str) |
|
| 1404 | + { |
|
| 1144 | 1405 | return count(preg_split('~[^\p{L}\p{N}\']+~u',$str)); |
| 1145 | 1406 | } |
| 1146 | - public function strip_tags($value,$params='') { |
|
| 1407 | + public function strip_tags($value,$params='') |
|
| 1408 | + { |
|
| 1147 | 1409 | global $modx; |
| 1148 | 1410 | |
| 1149 | 1411 | if(stripos($params,'style')===false && stripos($value,'</style>')!==false) { |
@@ -349,7 +349,7 @@ |
||
| 349 | 349 | $conditional = join(' ',$this->condition); |
| 350 | 350 | $isvalid = (int)(eval("return ({$conditional});")); |
| 351 | 351 | if ($isvalid) return $this->srcValue; |
| 352 | - return NULL; |
|
| 352 | + return null; |
|
| 353 | 353 | case 'then': |
| 354 | 354 | $conditional = join(' ',$this->condition); |
| 355 | 355 | $isvalid = (int)eval("return ({$conditional});"); |
@@ -8,8 +8,8 @@ |
||
| 8 | 8 | ******************************************************* |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -use PHPMailer\PHPMailer\PHPMailer; |
|
| 12 | 11 | use PHPMailer\PHPMailer\Exception as PHPMailerException; |
| 12 | +use PHPMailer\PHPMailer\PHPMailer; |
|
| 13 | 13 | |
| 14 | 14 | require MODX_MANAGER_PATH . 'includes/controls/phpmailer/Exception.php'; |
| 15 | 15 | require MODX_MANAGER_PATH . 'includes/controls/phpmailer/PHPMailer.php'; |
@@ -11,9 +11,9 @@ discard block |
||
| 11 | 11 | use PHPMailer\PHPMailer\PHPMailer; |
| 12 | 12 | use PHPMailer\PHPMailer\Exception as PHPMailerException; |
| 13 | 13 | |
| 14 | -require MODX_MANAGER_PATH . 'includes/controls/phpmailer/Exception.php'; |
|
| 15 | -require MODX_MANAGER_PATH . 'includes/controls/phpmailer/PHPMailer.php'; |
|
| 16 | -require MODX_MANAGER_PATH . 'includes/controls/phpmailer/SMTP.php'; |
|
| 14 | +require MODX_MANAGER_PATH.'includes/controls/phpmailer/Exception.php'; |
|
| 15 | +require MODX_MANAGER_PATH.'includes/controls/phpmailer/PHPMailer.php'; |
|
| 16 | +require MODX_MANAGER_PATH.'includes/controls/phpmailer/SMTP.php'; |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Class MODxMailer |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | public function init(DocumentParser $modx) |
| 36 | 36 | { |
| 37 | 37 | $this->modx = $modx; |
| 38 | - $this->PluginDir = MODX_MANAGER_PATH . 'includes/controls/phpmailer/'; |
|
| 38 | + $this->PluginDir = MODX_MANAGER_PATH.'includes/controls/phpmailer/'; |
|
| 39 | 39 | |
| 40 | 40 | switch ($modx->config['email_method']) { |
| 41 | 41 | case 'smtp': |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | mb_language($this->mb_language); |
| 100 | 100 | mb_internal_encoding($modx->config['modx_charset']); |
| 101 | 101 | } |
| 102 | - $exconf = MODX_MANAGER_PATH . 'includes/controls/phpmailer/config.inc.php'; |
|
| 102 | + $exconf = MODX_MANAGER_PATH.'includes/controls/phpmailer/config.inc.php'; |
|
| 103 | 103 | if (is_file($exconf)) { |
| 104 | 104 | include($exconf); |
| 105 | 105 | } |
@@ -167,12 +167,12 @@ discard block |
||
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | if ($this->modx->debug) { |
| 170 | - $debug_info = 'CharSet = ' . $this->CharSet . "\n"; |
|
| 171 | - $debug_info .= 'Encoding = ' . $this->Encoding . "\n"; |
|
| 172 | - $debug_info .= 'mb_language = ' . $this->mb_language . "\n"; |
|
| 173 | - $debug_info .= 'encode_header_method = ' . $this->encode_header_method . "\n"; |
|
| 170 | + $debug_info = 'CharSet = '.$this->CharSet."\n"; |
|
| 171 | + $debug_info .= 'Encoding = '.$this->Encoding."\n"; |
|
| 172 | + $debug_info .= 'mb_language = '.$this->mb_language."\n"; |
|
| 173 | + $debug_info .= 'encode_header_method = '.$this->encode_header_method."\n"; |
|
| 174 | 174 | $debug_info .= "send_mode = {$mode}\n"; |
| 175 | - $debug_info .= 'Subject = ' . $this->Subject . "\n"; |
|
| 175 | + $debug_info .= 'Subject = '.$this->Subject."\n"; |
|
| 176 | 176 | $log = "<pre>{$debug_info}\n{$header}\n{$org_body}</pre>"; |
| 177 | 177 | $this->modx->logEvent(1, 1, $log, 'MODxMailer debug information'); |
| 178 | 178 | |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | ini_set('sendmail_from', $old_from); |
| 237 | 237 | } |
| 238 | 238 | if (!$rt) { |
| 239 | - $msg = $this->Lang('instantiate') . "<br />\n"; |
|
| 239 | + $msg = $this->Lang('instantiate')."<br />\n"; |
|
| 240 | 240 | $msg .= "{$this->Subject}<br />\n"; |
| 241 | 241 | $msg .= "{$this->FromName}<{$this->From}><br />\n"; |
| 242 | 242 | $msg .= mb_convert_encoding($body, $this->modx->config['modx_charset'], $this->CharSet); |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | */ |
| 256 | 256 | public function SetError($msg) |
| 257 | 257 | { |
| 258 | - $msg .= '<pre>' . print_r(get_object_vars($this), true) . '</pre>'; |
|
| 258 | + $msg .= '<pre>'.print_r(get_object_vars($this), true).'</pre>'; |
|
| 259 | 259 | $this->modx->config['send_errormail'] = '0'; |
| 260 | 260 | $this->modx->logEvent(0, 3, $msg, 'phpmailer'); |
| 261 | 261 | |
@@ -284,14 +284,14 @@ discard block |
||
| 284 | 284 | /** |
| 285 | 285 | * @return string |
| 286 | 286 | */ |
| 287 | - public function getMIMEHeader() { |
|
| 287 | + public function getMIMEHeader(){ |
|
| 288 | 288 | return $this->MIMEHeader; |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
| 292 | 292 | * @return string |
| 293 | 293 | */ |
| 294 | - public function getMIMEBody() { |
|
| 294 | + public function getMIMEBody(){ |
|
| 295 | 295 | return $this->MIMEBody; |
| 296 | 296 | } |
| 297 | 297 | |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | * |
| 301 | 301 | * @return $this |
| 302 | 302 | */ |
| 303 | - public function setMIMEHeader($header = '') { |
|
| 303 | + public function setMIMEHeader($header = ''){ |
|
| 304 | 304 | $this->MIMEHeader = $header; |
| 305 | 305 | |
| 306 | 306 | return $this; |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | * |
| 312 | 312 | * @return $this |
| 313 | 313 | */ |
| 314 | - public function setMIMEBody($body = '') { |
|
| 314 | + public function setMIMEBody($body = ''){ |
|
| 315 | 315 | $this->MIMEBody = $body; |
| 316 | 316 | |
| 317 | 317 | return $this; |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | * |
| 323 | 323 | * @return $this |
| 324 | 324 | */ |
| 325 | - public function setMailHeader($header = '') { |
|
| 325 | + public function setMailHeader($header = ''){ |
|
| 326 | 326 | $this->mailHeader = $header; |
| 327 | 327 | |
| 328 | 328 | return $this; |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | /** |
| 332 | 332 | * @return string |
| 333 | 333 | */ |
| 334 | - public function getMessageID() { |
|
| 335 | - return trim($this->lastMessageID,'<>'); |
|
| 334 | + public function getMessageID(){ |
|
| 335 | + return trim($this->lastMessageID, '<>'); |
|
| 336 | 336 | } |
| 337 | 337 | } |