@@ -266,18 +266,18 @@ discard block |
||
| 266 | 266 | * @param string $str строка с фильтром |
| 267 | 267 | * @return array массив субфильтров |
| 268 | 268 | */ |
| 269 | - public function smartSplit($str){
|
|
| 269 | + public function smartSplit($str) {
|
|
| 270 | 270 | $res = array(); |
| 271 | 271 | $cur = ''; |
| 272 | 272 | $open = 0; |
| 273 | 273 | $strlen = mb_strlen($str, 'UTF-8'); |
| 274 | - for($i=0;$i<=$strlen;$i++){
|
|
| 274 | + for ($i = 0; $i <= $strlen; $i++) {
|
|
| 275 | 275 | $e = mb_substr($str, $i, 1, 'UTF-8'); |
| 276 | - switch($e){
|
|
| 276 | + switch ($e) {
|
|
| 277 | 277 | case ')': {
|
| 278 | 278 | $open--; |
| 279 | - if($open == 0){
|
|
| 280 | - $res[] = $cur.')'; |
|
| 279 | + if ($open == 0) {
|
|
| 280 | + $res[] = $cur . ')'; |
|
| 281 | 281 | $cur = ''; |
| 282 | 282 | } else {
|
| 283 | 283 | $cur .= $e; |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | break; |
| 291 | 291 | } |
| 292 | 292 | case ';':{
|
| 293 | - if($open == 0){
|
|
| 293 | + if ($open == 0) {
|
|
| 294 | 294 | $res[] = $cur; |
| 295 | 295 | $cur = ''; |
| 296 | 296 | } else {
|
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | $cur = preg_replace("/(\))$/u", '', $cur);
|
| 307 | - if ($cur != ''){
|
|
| 307 | + if ($cur != '') {
|
|
| 308 | 308 | $res[] = $cur; |
| 309 | 309 | } |
| 310 | 310 | return $res; |
@@ -432,14 +432,14 @@ discard block |
||
| 432 | 432 | $cfgName[1] = 'custom'; |
| 433 | 433 | } |
| 434 | 434 | $cfgName[1] = rtrim($cfgName[1], '/'); |
| 435 | - switch($cfgName[1]){
|
|
| 435 | + switch ($cfgName[1]) {
|
|
| 436 | 436 | case 'custom': |
| 437 | 437 | case 'core':{
|
| 438 | 438 | $configFile = dirname(dirname(__FILE__)) . "/config/{$cfgName[1]}/{$cfgName[0]}.json";
|
| 439 | 439 | break; |
| 440 | 440 | } |
| 441 | 441 | default:{
|
| 442 | - $configFile = $this->FS->relativePath( $cfgName[1] . '/' . $cfgName[0] . ".json"); |
|
| 442 | + $configFile = $this->FS->relativePath($cfgName[1] . '/' . $cfgName[0] . ".json"); |
|
| 443 | 443 | break; |
| 444 | 444 | } |
| 445 | 445 | } |
@@ -608,7 +608,7 @@ discard block |
||
| 608 | 608 | * |
| 609 | 609 | * @return int |
| 610 | 610 | */ |
| 611 | - public function getCurrentMODXPageID(){
|
|
| 611 | + public function getCurrentMODXPageID() {
|
|
| 612 | 612 | $id = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0; |
| 613 | 613 | $docData = isset($this->modx->documentObject) ? $this->modx->documentObject : array(); |
| 614 | 614 | |
@@ -745,7 +745,7 @@ discard block |
||
| 745 | 745 | $out = DLTemplate::getInstance($this->getMODX())->toPlaceholders($data, $set, $key, $id); |
| 746 | 746 | |
| 747 | 747 | $this->debug->debugEnd( |
| 748 | - "toPlaceholders", array($key ." placeholder" => $data), array('html')
|
|
| 748 | + "toPlaceholders", array($key . " placeholder" => $data), array('html')
|
|
| 749 | 749 | ); |
| 750 | 750 | return $out; |
| 751 | 751 | } |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | } |
| 768 | 768 | $out = array(); |
| 769 | 769 | foreach ($data as $item) {
|
| 770 | - if($item !== ''){
|
|
| 770 | + if ($item !== '') {
|
|
| 771 | 771 | $out[] = $this->modx->db->escape($item); |
| 772 | 772 | } |
| 773 | 773 | } |
@@ -991,11 +991,11 @@ discard block |
||
| 991 | 991 | * @param string $data html код который нужно обернуть в ownerTPL |
| 992 | 992 | * @return string результатирующий html код |
| 993 | 993 | */ |
| 994 | - public function renderWrap($data){
|
|
| 994 | + public function renderWrap($data) {
|
|
| 995 | 995 | $out = $data; |
| 996 | 996 | $docs = count($this->_docs) - $this->skippedDocs; |
| 997 | 997 | if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) {
|
| 998 | - $this->debug->debug("","renderWrapTPL",2);
|
|
| 998 | + $this->debug->debug("", "renderWrapTPL", 2);
|
|
| 999 | 999 | $parse = true; |
| 1000 | 1000 | $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data);
|
| 1001 | 1001 | /** |
@@ -1011,13 +1011,13 @@ discard block |
||
| 1011 | 1011 | 'nameParam' => 'prepareWrap', |
| 1012 | 1012 | 'return' => 'placeholders' |
| 1013 | 1013 | )); |
| 1014 | - if (is_bool($params) && $params === false){
|
|
| 1014 | + if (is_bool($params) && $params === false) {
|
|
| 1015 | 1015 | $out = $data; |
| 1016 | 1016 | $parse = false; |
| 1017 | 1017 | } |
| 1018 | 1018 | $plh = $params; |
| 1019 | 1019 | } |
| 1020 | - if($parse && !empty($this->ownerTPL)){
|
|
| 1020 | + if ($parse && !empty($this->ownerTPL)) {
|
|
| 1021 | 1021 | $this->debug->updateMessage( |
| 1022 | 1022 | array("render ownerTPL" => $this->ownerTPL, "With data" => print_r($plh, 1)),
|
| 1023 | 1023 | "renderWrapTPL", |
@@ -1025,7 +1025,7 @@ discard block |
||
| 1025 | 1025 | ); |
| 1026 | 1026 | $out = $this->parseChunk($this->ownerTPL, $plh); |
| 1027 | 1027 | } |
| 1028 | - if(empty($this->ownerTPL)){
|
|
| 1028 | + if (empty($this->ownerTPL)) {
|
|
| 1029 | 1029 | $this->debug->updateMessage("empty ownerTPL", "renderWrapTPL");
|
| 1030 | 1030 | } |
| 1031 | 1031 | $this->debug->debugEnd("renderWrapTPL");
|
@@ -1039,12 +1039,12 @@ discard block |
||
| 1039 | 1039 | * @param int $i номер итерации в цикле |
| 1040 | 1040 | * @return array массив с данными которые можно использовать в цикле render метода |
| 1041 | 1041 | */ |
| 1042 | - protected function uniformPrepare(&$data, $i=0){
|
|
| 1042 | + protected function uniformPrepare(&$data, $i = 0) {
|
|
| 1043 | 1043 | $class = array(); |
| 1044 | 1044 | |
| 1045 | 1045 | $iterationName = ($i % 2 == 0) ? 'Odd' : 'Even'; |
| 1046 | 1046 | $tmp = strtolower($iterationName); |
| 1047 | - $class[] = $this->getCFGDef($tmp.'Class', $tmp); |
|
| 1047 | + $class[] = $this->getCFGDef($tmp . 'Class', $tmp); |
|
| 1048 | 1048 | |
| 1049 | 1049 | $this->renderTPL = $this->getCFGDef('tplId' . $i, $this->renderTPL);
|
| 1050 | 1050 | $this->renderTPL = $this->getCFGDef('tpl' . $iterationName, $this->renderTPL);
|
@@ -1074,9 +1074,9 @@ discard block |
||
| 1074 | 1074 | * @var $extE e_DL_Extender |
| 1075 | 1075 | */ |
| 1076 | 1076 | $extE = $this->getExtender('e', true, true);
|
| 1077 | - if($out = $extE->init($this, compact('data'))){
|
|
| 1078 | - if(is_array($out)){
|
|
| 1079 | - $data = $out; |
|
| 1077 | + if ($out = $extE->init($this, compact('data'))) {
|
|
| 1078 | + if (is_array($out)) {
|
|
| 1079 | + $data = $out; |
|
| 1080 | 1080 | } |
| 1081 | 1081 | } |
| 1082 | 1082 | return compact('class', 'iterationName');
|
@@ -1310,7 +1310,7 @@ discard block |
||
| 1310 | 1310 | return $out; |
| 1311 | 1311 | } |
| 1312 | 1312 | |
| 1313 | - public function docsCollection(){
|
|
| 1313 | + public function docsCollection() {
|
|
| 1314 | 1314 | return new DLCollection($this->modx, $this->_docs); |
| 1315 | 1315 | } |
| 1316 | 1316 | |
@@ -1475,18 +1475,18 @@ discard block |
||
| 1475 | 1475 | $children = array(); // children of each ID |
| 1476 | 1476 | $ids = array(); |
| 1477 | 1477 | foreach ($data as $i => $r) {
|
| 1478 | - $row =& $data[$i]; |
|
| 1478 | + $row = & $data[$i]; |
|
| 1479 | 1479 | $id = $row[$idName]; |
| 1480 | 1480 | $pid = $row[$pidName]; |
| 1481 | - $children[$pid][$id] =& $row; |
|
| 1481 | + $children[$pid][$id] = & $row; |
|
| 1482 | 1482 | if (!isset($children[$id])) $children[$id] = array(); |
| 1483 | - $row['#childNodes'] =& $children[$id]; |
|
| 1483 | + $row['#childNodes'] = & $children[$id]; |
|
| 1484 | 1484 | $ids[$row[$idName]] = true; |
| 1485 | 1485 | } |
| 1486 | 1486 | // Root elements are elements with non-found PIDs. |
| 1487 | 1487 | $this->_tree = array(); |
| 1488 | 1488 | foreach ($data as $i => $r) {
|
| 1489 | - $row =& $data[$i]; |
|
| 1489 | + $row = & $data[$i]; |
|
| 1490 | 1490 | if (!isset($ids[$row[$pidName]])) {
|
| 1491 | 1491 | $this->_tree[$row[$idName]] = $row; |
| 1492 | 1492 | } |
@@ -1511,7 +1511,7 @@ discard block |
||
| 1511 | 1511 | * По умолчанию это parent. Переопределить можно в контроллере присвоив другое значение переменной parentField |
| 1512 | 1512 | * @return string Parent Key основной таблицы |
| 1513 | 1513 | */ |
| 1514 | - public function getParentField(){
|
|
| 1514 | + public function getParentField() {
|
|
| 1515 | 1515 | return isset($this->parentField) ? $this->parentField : ''; |
| 1516 | 1516 | } |
| 1517 | 1517 | /** |
@@ -199,7 +199,9 @@ discard block |
||
| 199 | 199 | $this->setDebug(1); |
| 200 | 200 | $this->loadLang(array('core', 'json'));
|
| 201 | 201 | |
| 202 | - if (!is_array($cfg) || empty($cfg)) $cfg = $this->modx->Event->params; |
|
| 202 | + if (!is_array($cfg) || empty($cfg)) {
|
|
| 203 | + $cfg = $this->modx->Event->params; |
|
| 204 | + } |
|
| 203 | 205 | } else {
|
| 204 | 206 | throw new Exception('MODX var is not instaceof DocumentParser');
|
| 205 | 207 | } |
@@ -741,7 +743,9 @@ discard block |
||
| 741 | 743 | } |
| 742 | 744 | $this->_plh[$key] = $data; |
| 743 | 745 | $id = $this->getCFGDef('id', '');
|
| 744 | - if ($id != '') $id .= "."; |
|
| 746 | + if ($id != '') {
|
|
| 747 | + $id .= "."; |
|
| 748 | + } |
|
| 745 | 749 | $out = DLTemplate::getInstance($this->getMODX())->toPlaceholders($data, $set, $key, $id); |
| 746 | 750 | |
| 747 | 751 | $this->debug->debugEnd( |
@@ -1479,7 +1483,9 @@ discard block |
||
| 1479 | 1483 | $id = $row[$idName]; |
| 1480 | 1484 | $pid = $row[$pidName]; |
| 1481 | 1485 | $children[$pid][$id] =& $row; |
| 1482 | - if (!isset($children[$id])) $children[$id] = array(); |
|
| 1486 | + if (!isset($children[$id])) {
|
|
| 1487 | + $children[$id] = array(); |
|
| 1488 | + } |
|
| 1483 | 1489 | $row['#childNodes'] =& $children[$id]; |
| 1484 | 1490 | $ids[$row[$idName]] = true; |
| 1485 | 1491 | } |
@@ -1526,7 +1532,9 @@ discard block |
||
| 1526 | 1532 | $this->debug->debug("getFilters: " . $this->debug->dumpData($filter_string), 'getFilter', 1);
|
| 1527 | 1533 | // the filter parameter tells us, which filters can be used in this query |
| 1528 | 1534 | $filter_string = trim($filter_string, ' ;'); |
| 1529 | - if (!$filter_string) return; |
|
| 1535 | + if (!$filter_string) {
|
|
| 1536 | + return; |
|
| 1537 | + } |
|
| 1530 | 1538 | $output = array('join' => '', 'where' => '');
|
| 1531 | 1539 | $logic_op_found = false; |
| 1532 | 1540 | $joins = $wheres = array(); |
@@ -1537,9 +1545,15 @@ discard block |
||
| 1537 | 1545 | $subfilters = $this->smartSplit($subfilters); |
| 1538 | 1546 | foreach ($subfilters as $subfilter) {
|
| 1539 | 1547 | $subfilter = $this->getFilters(trim($subfilter)); |
| 1540 | - if (!$subfilter) continue; |
|
| 1541 | - if ($subfilter['join']) $joins[] = $subfilter['join']; |
|
| 1542 | - if ($subfilter['where']) $wheres[] = $subfilter['where']; |
|
| 1548 | + if (!$subfilter) {
|
|
| 1549 | + continue; |
|
| 1550 | + } |
|
| 1551 | + if ($subfilter['join']) {
|
|
| 1552 | + $joins[] = $subfilter['join']; |
|
| 1553 | + } |
|
| 1554 | + if ($subfilter['where']) {
|
|
| 1555 | + $wheres[] = $subfilter['where']; |
|
| 1556 | + } |
|
| 1543 | 1557 | } |
| 1544 | 1558 | $output['join'] = !empty($joins) ? implode(' ', $joins) : '';
|
| 1545 | 1559 | $output['where'] = !empty($wheres) ? '(' . implode($sql, $wheres) . ')' : '';
|
@@ -3,20 +3,20 @@ discard block |
||
| 3 | 3 | die('HACK???');
|
| 4 | 4 | } |
| 5 | 5 | /** |
| 6 | - * DocLister class |
|
| 7 | - * |
|
| 8 | - * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html |
|
| 9 | - * @author Agel_Nash <[email protected]> |
|
| 10 | - * |
|
| 11 | - * @TODO add controller for work with plugin http://modx.com/extras/package/quid and get TV value via LEFT JOIN |
|
| 12 | - * @TODO add controller for filter by TV values |
|
| 13 | - * @TODO add method load default template |
|
| 14 | - * @TODO add example custom controller for build google sitemap.xml |
|
| 15 | - * @TODO add method build tree for replace Wayfinder if need TV value in menu OR sitemap |
|
| 16 | - * @TODO add controller for show list web-user with filter by group and other user information |
|
| 17 | - * @TODO depending on the parameters |
|
| 18 | - * @TODO prepare value before return final data (maybe callback function OR extender) |
|
| 19 | - */ |
|
| 6 | + * DocLister class |
|
| 7 | + * |
|
| 8 | + * @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html |
|
| 9 | + * @author Agel_Nash <[email protected]> |
|
| 10 | + * |
|
| 11 | + * @TODO add controller for work with plugin http://modx.com/extras/package/quid and get TV value via LEFT JOIN |
|
| 12 | + * @TODO add controller for filter by TV values |
|
| 13 | + * @TODO add method load default template |
|
| 14 | + * @TODO add example custom controller for build google sitemap.xml |
|
| 15 | + * @TODO add method build tree for replace Wayfinder if need TV value in menu OR sitemap |
|
| 16 | + * @TODO add controller for show list web-user with filter by group and other user information |
|
| 17 | + * @TODO depending on the parameters |
|
| 18 | + * @TODO prepare value before return final data (maybe callback function OR extender) |
|
| 19 | + */ |
|
| 20 | 20 | include_once(MODX_BASE_PATH . 'assets/lib/APIHelpers.class.php'); |
| 21 | 21 | include_once(MODX_BASE_PATH . 'assets/lib/Helpers/FS.php'); |
| 22 | 22 | require_once(dirname(dirname(__FILE__)) . "/lib/jsonHelper.class.php"); |
@@ -107,10 +107,10 @@ discard block |
||
| 107 | 107 | protected $idField = 'id'; |
| 108 | 108 | |
| 109 | 109 | /** |
| 110 | - * Parent Key основной таблицы |
|
| 111 | - * @var string |
|
| 112 | - * @access protected |
|
| 113 | - */ |
|
| 110 | + * Parent Key основной таблицы |
|
| 111 | + * @var string |
|
| 112 | + * @access protected |
|
| 113 | + */ |
|
| 114 | 114 | protected $parentField = 'parent'; |
| 115 | 115 | /** |
| 116 | 116 | * Дополнительные условия для SQL запросов |
@@ -168,18 +168,18 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | public $FS = null; |
| 170 | 170 | /** @var string результатирующая строка которая была последний раз сгенирирована |
| 171 | - * вызовами методов DocLister::render и DocLister::getJSON |
|
| 172 | - */ |
|
| 171 | + * вызовами методов DocLister::render и DocLister::getJSON |
|
| 172 | + */ |
|
| 173 | 173 | protected $outData = ''; |
| 174 | 174 | |
| 175 | - /** @var int Число документов, которые были отфильтрованы через prepare при выводе */ |
|
| 176 | - public $skippedDocs = 0; |
|
| 175 | + /** @var int Число документов, которые были отфильтрованы через prepare при выводе */ |
|
| 176 | + public $skippedDocs = 0; |
|
| 177 | 177 | |
| 178 | - /** @var string Имя таблицы */ |
|
| 179 | - protected $table = ''; |
|
| 178 | + /** @var string Имя таблицы */ |
|
| 179 | + protected $table = ''; |
|
| 180 | 180 | |
| 181 | - /** @var null|paginate_DL_Extender */ |
|
| 182 | - protected $extPaginate = null; |
|
| 181 | + /** @var null|paginate_DL_Extender */ |
|
| 182 | + protected $extPaginate = null; |
|
| 183 | 183 | /** |
| 184 | 184 | * Конструктор контроллеров DocLister |
| 185 | 185 | * |
@@ -191,30 +191,30 @@ discard block |
||
| 191 | 191 | {
|
| 192 | 192 | $this->setTimeStart($startTime); |
| 193 | 193 | |
| 194 | - if (extension_loaded('mbstring')) {
|
|
| 195 | - mb_internal_encoding("UTF-8");
|
|
| 196 | - } else {
|
|
| 197 | - throw new Exception('Not found php extension mbstring');
|
|
| 198 | - } |
|
| 194 | + if (extension_loaded('mbstring')) {
|
|
| 195 | + mb_internal_encoding("UTF-8");
|
|
| 196 | + } else {
|
|
| 197 | + throw new Exception('Not found php extension mbstring');
|
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | 200 | if ($modx instanceof DocumentParser) {
|
| 201 | - $this->modx = $modx; |
|
| 201 | + $this->modx = $modx; |
|
| 202 | 202 | $this->setDebug(1); |
| 203 | 203 | $this->loadLang(array('core', 'json'));
|
| 204 | 204 | |
| 205 | 205 | if (!is_array($cfg) || empty($cfg)) $cfg = $this->modx->Event->params; |
| 206 | - } else {
|
|
| 207 | - throw new Exception('MODX var is not instaceof DocumentParser');
|
|
| 208 | - } |
|
| 206 | + } else {
|
|
| 207 | + throw new Exception('MODX var is not instaceof DocumentParser');
|
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | 210 | $this->FS = \Helpers\FS::getInstance(); |
| 211 | 211 | if (isset($cfg['config'])) {
|
| 212 | - $cfg = array_merge($this->loadConfig($cfg['config']), $cfg); |
|
| 213 | - } |
|
| 212 | + $cfg = array_merge($this->loadConfig($cfg['config']), $cfg); |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - if (!$this->setConfig($cfg)) {
|
|
| 216 | - throw new Exception('no parameters to run DocLister');
|
|
| 217 | - } |
|
| 215 | + if (!$this->setConfig($cfg)) {
|
|
| 216 | + throw new Exception('no parameters to run DocLister');
|
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | 219 | $this->setDebug($this->getCFGDef('debug', 0));
|
| 220 | 220 | |
@@ -262,48 +262,48 @@ discard block |
||
| 262 | 262 | |
| 263 | 263 | /** |
| 264 | 264 | * Разбиение фильтра на субфильтры с учётом вложенности |
| 265 | - * @param string $str строка с фильтром |
|
| 265 | + * @param string $str строка с фильтром |
|
| 266 | 266 | * @return array массив субфильтров |
| 267 | 267 | */ |
| 268 | - public function smartSplit($str){
|
|
| 269 | - $res = array(); |
|
| 270 | - $cur = ''; |
|
| 271 | - $open = 0; |
|
| 272 | - $strlen = mb_strlen($str, 'UTF-8'); |
|
| 273 | - for($i=0;$i<=$strlen;$i++){
|
|
| 274 | - $e = mb_substr($str, $i, 1, 'UTF-8'); |
|
| 275 | - switch($e){
|
|
| 276 | - case ')': |
|
| 277 | - $open--; |
|
| 278 | - if($open == 0){
|
|
| 279 | - $res[] = $cur.')'; |
|
| 280 | - $cur = ''; |
|
| 281 | - } else {
|
|
| 282 | - $cur .= $e; |
|
| 283 | - } |
|
| 284 | - break; |
|
| 285 | - case '(':
|
|
| 286 | - $open++; |
|
| 287 | - $cur .= $e; |
|
| 288 | - break; |
|
| 289 | - case ';': |
|
| 290 | - if($open == 0){
|
|
| 291 | - $res[] = $cur; |
|
| 292 | - $cur = ''; |
|
| 293 | - } else {
|
|
| 294 | - $cur .= $e; |
|
| 295 | - } |
|
| 296 | - break; |
|
| 297 | - default: |
|
| 298 | - $cur .= $e; |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - $cur = preg_replace("/(\))$/u", '', $cur);
|
|
| 302 | - if ($cur != ''){
|
|
| 303 | - $res[] = $cur; |
|
| 304 | - } |
|
| 305 | - return $res; |
|
| 306 | - } |
|
| 268 | + public function smartSplit($str){
|
|
| 269 | + $res = array(); |
|
| 270 | + $cur = ''; |
|
| 271 | + $open = 0; |
|
| 272 | + $strlen = mb_strlen($str, 'UTF-8'); |
|
| 273 | + for($i=0;$i<=$strlen;$i++){
|
|
| 274 | + $e = mb_substr($str, $i, 1, 'UTF-8'); |
|
| 275 | + switch($e){
|
|
| 276 | + case ')': |
|
| 277 | + $open--; |
|
| 278 | + if($open == 0){
|
|
| 279 | + $res[] = $cur.')'; |
|
| 280 | + $cur = ''; |
|
| 281 | + } else {
|
|
| 282 | + $cur .= $e; |
|
| 283 | + } |
|
| 284 | + break; |
|
| 285 | + case '(':
|
|
| 286 | + $open++; |
|
| 287 | + $cur .= $e; |
|
| 288 | + break; |
|
| 289 | + case ';': |
|
| 290 | + if($open == 0){
|
|
| 291 | + $res[] = $cur; |
|
| 292 | + $cur = ''; |
|
| 293 | + } else {
|
|
| 294 | + $cur .= $e; |
|
| 295 | + } |
|
| 296 | + break; |
|
| 297 | + default: |
|
| 298 | + $cur .= $e; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + $cur = preg_replace("/(\))$/u", '', $cur);
|
|
| 302 | + if ($cur != ''){
|
|
| 303 | + $res[] = $cur; |
|
| 304 | + } |
|
| 305 | + return $res; |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | 308 | /** |
| 309 | 309 | * Трансформация объекта в строку |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | $flag = true; |
| 492 | 492 | $extenders = $this->getCFGDef('extender', '');
|
| 493 | 493 | $extenders = explode(",", $extenders);
|
| 494 | - if (($this->getCFGDef('requestActive', '') != '' || in_array('request', $extenders)) && !$this->_loadExtender('request')) { //OR request in extender's parameter
|
|
| 494 | + if (($this->getCFGDef('requestActive', '') != '' || in_array('request', $extenders)) && !$this->_loadExtender('request')) { //OR request in extender's parameter
|
|
| 495 | 495 | throw new Exception('Error load request extender');
|
| 496 | 496 | } |
| 497 | 497 | |
@@ -595,17 +595,17 @@ discard block |
||
| 595 | 595 | ****************** CORE Block ********************* |
| 596 | 596 | ***************************************************/ |
| 597 | 597 | |
| 598 | - /** |
|
| 599 | - * Определение ID страницы открытой во фронте |
|
| 600 | - * |
|
| 601 | - * @return int |
|
| 602 | - */ |
|
| 603 | - public function getCurrentMODXPageID(){
|
|
| 604 | - $id = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0; |
|
| 605 | - $docData = isset($this->modx->documentObject) ? $this->modx->documentObject : array(); |
|
| 598 | + /** |
|
| 599 | + * Определение ID страницы открытой во фронте |
|
| 600 | + * |
|
| 601 | + * @return int |
|
| 602 | + */ |
|
| 603 | + public function getCurrentMODXPageID(){
|
|
| 604 | + $id = isset($this->modx->documentIdentifier) ? (int)$this->modx->documentIdentifier : 0; |
|
| 605 | + $docData = isset($this->modx->documentObject) ? $this->modx->documentObject : array(); |
|
| 606 | 606 | |
| 607 | - return empty($id) ? \APIHelpers::getkey($docData, 'id', 0) : $id; |
|
| 608 | - } |
|
| 607 | + return empty($id) ? \APIHelpers::getkey($docData, 'id', 0) : $id; |
|
| 608 | + } |
|
| 609 | 609 | |
| 610 | 610 | /** |
| 611 | 611 | * Display and save error information |
@@ -653,14 +653,14 @@ discard block |
||
| 653 | 653 | $ext = explode(",", $ext);
|
| 654 | 654 | foreach ($ext as $item) {
|
| 655 | 655 | if ($item != '' && !$this->_loadExtender($item)) {
|
| 656 | - throw new Exception('Error load ' . APIHelpers::e($item) . ' extender');
|
|
| 657 | - } |
|
| 656 | + throw new Exception('Error load ' . APIHelpers::e($item) . ' extender');
|
|
| 657 | + } |
|
| 658 | 658 | } |
| 659 | 659 | } |
| 660 | 660 | return $out; |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | - /** |
|
| 663 | + /** |
|
| 664 | 664 | * Получение всего списка настроек |
| 665 | 665 | * @return array |
| 666 | 666 | */ |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | */ |
| 677 | 677 | public function setConfig($cfg) |
| 678 | 678 | {
|
| 679 | - if (is_array($cfg)) {
|
|
| 679 | + if (is_array($cfg)) {
|
|
| 680 | 680 | $this->_cfg = array_merge($this->_cfg, $cfg); |
| 681 | 681 | $ret = count($this->_cfg); |
| 682 | 682 | } else {
|
@@ -685,7 +685,7 @@ discard block |
||
| 685 | 685 | return $ret; |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | - /** |
|
| 688 | + /** |
|
| 689 | 689 | * Полная перезапись настроек вызова сниппета |
| 690 | 690 | * @param array $cfg массив настроек |
| 691 | 691 | * @return int Общее число новых настроек |
@@ -693,9 +693,9 @@ discard block |
||
| 693 | 693 | public function replaceConfig($cfg) |
| 694 | 694 | {
|
| 695 | 695 | if (!is_array($cfg)) {
|
| 696 | - $cfg = array(); |
|
| 696 | + $cfg = array(); |
|
| 697 | 697 | } |
| 698 | - $this->_cfg = $cfg; |
|
| 698 | + $this->_cfg = $cfg; |
|
| 699 | 699 | return count($this->_cfg); |
| 700 | 700 | } |
| 701 | 701 | |
@@ -979,21 +979,21 @@ discard block |
||
| 979 | 979 | */ |
| 980 | 980 | public function renderWrap($data){
|
| 981 | 981 | $out = $data; |
| 982 | - $docs = count($this->_docs) - $this->skippedDocs; |
|
| 983 | - if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) {
|
|
| 982 | + $docs = count($this->_docs) - $this->skippedDocs; |
|
| 983 | + if ((($this->getCFGDef("noneWrapOuter", "1") && $docs == 0) || $docs > 0) && !empty($this->ownerTPL)) {
|
|
| 984 | 984 | $this->debug->debug("","renderWrapTPL",2);
|
| 985 | 985 | $parse = true; |
| 986 | 986 | $plh = array($this->getCFGDef("sysKey", "dl") . ".wrap" => $data);
|
| 987 | 987 | /** |
| 988 | - * @var $extPrepare prepare_DL_Extender |
|
| 989 | - */ |
|
| 988 | + * @var $extPrepare prepare_DL_Extender |
|
| 989 | + */ |
|
| 990 | 990 | $extPrepare = $this->getExtender('prepare');
|
| 991 | 991 | if ($extPrepare) {
|
| 992 | 992 | $params = $extPrepare->init($this, array( |
| 993 | 993 | 'data' => array( |
| 994 | - 'docs' => $this->_docs, |
|
| 995 | - 'placeholders' => $plh |
|
| 996 | - ), |
|
| 994 | + 'docs' => $this->_docs, |
|
| 995 | + 'placeholders' => $plh |
|
| 996 | + ), |
|
| 997 | 997 | 'nameParam' => 'prepareWrap', |
| 998 | 998 | 'return' => 'placeholders' |
| 999 | 999 | )); |
@@ -1019,12 +1019,12 @@ discard block |
||
| 1019 | 1019 | return $out; |
| 1020 | 1020 | } |
| 1021 | 1021 | /** |
| 1022 | - * Единые обработки массива с данными о документе для всех контроллеров |
|
| 1023 | - * |
|
| 1024 | - * @param array $data массив с данными о текущем документе |
|
| 1025 | - * @param int $i номер итерации в цикле |
|
| 1026 | - * @return array массив с данными которые можно использовать в цикле render метода |
|
| 1027 | - */ |
|
| 1022 | + * Единые обработки массива с данными о документе для всех контроллеров |
|
| 1023 | + * |
|
| 1024 | + * @param array $data массив с данными о текущем документе |
|
| 1025 | + * @param int $i номер итерации в цикле |
|
| 1026 | + * @return array массив с данными которые можно использовать в цикле render метода |
|
| 1027 | + */ |
|
| 1028 | 1028 | protected function uniformPrepare(&$data, $i=0){
|
| 1029 | 1029 | $class = array(); |
| 1030 | 1030 | |
@@ -1057,8 +1057,8 @@ discard block |
||
| 1057 | 1057 | $data[$this->getCFGDef("sysKey", "dl") . '.class'] = $class;
|
| 1058 | 1058 | |
| 1059 | 1059 | /** |
| 1060 | - * @var $extE e_DL_Extender |
|
| 1061 | - */ |
|
| 1060 | + * @var $extE e_DL_Extender |
|
| 1061 | + */ |
|
| 1062 | 1062 | $extE = $this->getExtender('e', true, true);
|
| 1063 | 1063 | if($out = $extE->init($this, compact('data'))){
|
| 1064 | 1064 | if(is_array($out)){
|
@@ -1296,7 +1296,7 @@ discard block |
||
| 1296 | 1296 | return $out; |
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | - public function docsCollection(){
|
|
| 1299 | + public function docsCollection(){
|
|
| 1300 | 1300 | return new DLCollection($this->modx, $this->_docs); |
| 1301 | 1301 | } |
| 1302 | 1302 | |
@@ -1485,10 +1485,10 @@ discard block |
||
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | /** |
| 1488 | - * Получение Parent key |
|
| 1489 | - * По умолчанию это parent. Переопределить можно в контроллере присвоив другое значение переменной parentField |
|
| 1490 | - * @return string Parent Key основной таблицы |
|
| 1491 | - */ |
|
| 1488 | + * Получение Parent key |
|
| 1489 | + * По умолчанию это parent. Переопределить можно в контроллере присвоив другое значение переменной parentField |
|
| 1490 | + * @return string Parent Key основной таблицы |
|
| 1491 | + */ |
|
| 1492 | 1492 | public function getParentField(){
|
| 1493 | 1493 | return isset($this->parentField) ? $this->parentField : ''; |
| 1494 | 1494 | } |
@@ -1507,7 +1507,7 @@ discard block |
||
| 1507 | 1507 | if (!$filter_string) return; |
| 1508 | 1508 | $output = array('join' => '', 'where' => '');
|
| 1509 | 1509 | $logic_op_found = false; |
| 1510 | - $joins = $wheres = array(); |
|
| 1510 | + $joins = $wheres = array(); |
|
| 1511 | 1511 | foreach ($this->_logic_ops as $op => $sql) {
|
| 1512 | 1512 | if (strpos($filter_string, $op) === 0) {
|
| 1513 | 1513 | $logic_op_found = true; |
@@ -13,23 +13,23 @@ discard block |
||
| 13 | 13 | protected $set = array(); |
| 14 | 14 | protected $newDoc = false; |
| 15 | 15 | protected $pkName = 'id'; |
| 16 | - protected $ignoreError = ''; |
|
| 16 | + protected $ignoreError = ''; |
|
| 17 | 17 | protected $_debug = false; |
| 18 | 18 | protected $_query = array(); |
| 19 | 19 | protected $jsonFields = array(); |
| 20 | - /** |
|
| 21 | - * @var DLCollection |
|
| 22 | - */ |
|
| 20 | + /** |
|
| 21 | + * @var DLCollection |
|
| 22 | + */ |
|
| 23 | 23 | private $_decodedFields; |
| 24 | - private $_table = array(); |
|
| 24 | + private $_table = array(); |
|
| 25 | 25 | |
| 26 | 26 | public function __construct(DocumentParser $modx, $debug = false) |
| 27 | 27 | {
|
| 28 | 28 | if(function_exists("get_magic_quotes_gpc") && get_magic_quotes_gpc()){
|
| 29 | - throw new Exception('Magic Quotes is a deprecated and mostly useless setting that should be disabled. Please ask your server administrator to disable it in php.ini or in your webserver config.');
|
|
| 30 | - } |
|
| 29 | + throw new Exception('Magic Quotes is a deprecated and mostly useless setting that should be disabled. Please ask your server administrator to disable it in php.ini or in your webserver config.');
|
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $this->setDebug($debug); |
|
| 32 | + $this->setDebug($debug); |
|
| 33 | 33 | $this->_decodedFields = new DLCollection($this->modx); |
| 34 | 34 | } |
| 35 | 35 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $value = $this->modx->db->escape($value); |
| 71 | 71 | } |
| 72 | 72 | return $value; |
| 73 | - } |
|
| 73 | + } |
|
| 74 | 74 | final public function invokeEvent($name, $data = array(), $flag = false) |
| 75 | 75 | {
|
| 76 | 76 | $flag = (isset($flag) && $flag != '') ? (bool)$flag : false; |
@@ -109,42 +109,42 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | final public function clearCache($fire_events = null, $custom = false) |
| 111 | 111 | {
|
| 112 | - $IDs = array(); |
|
| 113 | - if($custom === false) {
|
|
| 114 | - $this->modx->clearCache(); |
|
| 115 | - include_once(MODX_MANAGER_PATH . 'processors/cache_sync.class.processor.php'); |
|
| 116 | - $sync = new synccache(); |
|
| 117 | - $path = $this->getCachePath(true); |
|
| 118 | - $sync->setCachepath($path); |
|
| 119 | - $sync->setReport(false); |
|
| 120 | - $sync->emptyCache(); |
|
| 121 | - }else {
|
|
| 122 | - if(is_scalar($custom)){
|
|
| 123 | - $custom = array($custom); |
|
| 124 | - } |
|
| 125 | - switch ($this->modx->config['cache_type']) {
|
|
| 126 | - case 2: |
|
| 127 | - $cacheFile = "_*.pageCache.php"; |
|
| 128 | - break; |
|
| 129 | - default: |
|
| 130 | - $cacheFile = ".pageCache.php"; |
|
| 131 | - } |
|
| 132 | - if(is_array($custom)) {
|
|
| 133 | - foreach($custom as $id) {
|
|
| 134 | - $tmp = glob(MODX_BASE_PATH."assets/cache/docid_" . $id . $cacheFile); |
|
| 135 | - foreach($tmp as $file){
|
|
| 136 | - if(is_readable($file)){
|
|
| 137 | - unlink($file); |
|
| 138 | - } |
|
| 139 | - $IDs[] = $id; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - clearstatcache(); |
|
| 144 | - } |
|
| 112 | + $IDs = array(); |
|
| 113 | + if($custom === false) {
|
|
| 114 | + $this->modx->clearCache(); |
|
| 115 | + include_once(MODX_MANAGER_PATH . 'processors/cache_sync.class.processor.php'); |
|
| 116 | + $sync = new synccache(); |
|
| 117 | + $path = $this->getCachePath(true); |
|
| 118 | + $sync->setCachepath($path); |
|
| 119 | + $sync->setReport(false); |
|
| 120 | + $sync->emptyCache(); |
|
| 121 | + }else {
|
|
| 122 | + if(is_scalar($custom)){
|
|
| 123 | + $custom = array($custom); |
|
| 124 | + } |
|
| 125 | + switch ($this->modx->config['cache_type']) {
|
|
| 126 | + case 2: |
|
| 127 | + $cacheFile = "_*.pageCache.php"; |
|
| 128 | + break; |
|
| 129 | + default: |
|
| 130 | + $cacheFile = ".pageCache.php"; |
|
| 131 | + } |
|
| 132 | + if(is_array($custom)) {
|
|
| 133 | + foreach($custom as $id) {
|
|
| 134 | + $tmp = glob(MODX_BASE_PATH."assets/cache/docid_" . $id . $cacheFile); |
|
| 135 | + foreach($tmp as $file){
|
|
| 136 | + if(is_readable($file)){
|
|
| 137 | + unlink($file); |
|
| 138 | + } |
|
| 139 | + $IDs[] = $id; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + clearstatcache(); |
|
| 144 | + } |
|
| 145 | 145 | $this->invokeEvent('OnSiteRefresh', array('IDs' => $IDs), $fire_events);
|
| 146 | 146 | } |
| 147 | - public function switchObject($id){
|
|
| 147 | + public function switchObject($id){
|
|
| 148 | 148 | switch(true){
|
| 149 | 149 | //Если загружен другой объект - не тот, с которым мы хотим временно поработать |
| 150 | 150 | case ($this->getID() != $id && $id): |
@@ -161,13 +161,13 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | return $obj; |
| 163 | 163 | } |
| 164 | - public function useIgnore($flag = true){
|
|
| 165 | - $this->ignoreError = $flag ? 'IGNORE' : ''; |
|
| 166 | - return $this; |
|
| 167 | - } |
|
| 168 | - public function hasIgnore(){
|
|
| 169 | - return (bool)$this->ignoreError; |
|
| 170 | - } |
|
| 164 | + public function useIgnore($flag = true){
|
|
| 165 | + $this->ignoreError = $flag ? 'IGNORE' : ''; |
|
| 166 | + return $this; |
|
| 167 | + } |
|
| 168 | + public function hasIgnore(){
|
|
| 169 | + return (bool)$this->ignoreError; |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | 172 | public function set($key, $value) |
| 173 | 173 | {
|
@@ -204,8 +204,8 @@ discard block |
||
| 204 | 204 | $this->log[] = "{$key} is empty";
|
| 205 | 205 | } else {
|
| 206 | 206 | if ($this->issetField($key) && is_scalar($this->field[$key])) {
|
| 207 | - $tmp = "`{$key}`='{$this->escape($this->field[$key])}'";
|
|
| 208 | - } else throw new Exception("{$key} is invalid <pre>" . print_r($this->field[$key], true) . "</pre>");
|
|
| 207 | + $tmp = "`{$key}`='{$this->escape($this->field[$key])}'";
|
|
| 208 | + } else throw new Exception("{$key} is invalid <pre>" . print_r($this->field[$key], true) . "</pre>");
|
|
| 209 | 209 | } |
| 210 | 210 | if (!empty($tmp)) {
|
| 211 | 211 | if ($id == '') {
|
@@ -223,11 +223,11 @@ discard block |
||
| 223 | 223 | $out = array(); |
| 224 | 224 | if (!is_array($IDs)) {
|
| 225 | 225 | if (is_scalar($IDs)) {
|
| 226 | - $IDs = explode($sep, $IDs); |
|
| 227 | - } else {
|
|
| 228 | - $IDs = array(); |
|
| 226 | + $IDs = explode($sep, $IDs); |
|
| 227 | + } else {
|
|
| 228 | + $IDs = array(); |
|
| 229 | 229 | throw new Exception('Invalid IDs list <pre>' . print_r($IDs, 1) . '</pre>');
|
| 230 | - } |
|
| 230 | + } |
|
| 231 | 231 | } |
| 232 | 232 | foreach ($IDs as $item) {
|
| 233 | 233 | $item = trim($item); |
@@ -246,38 +246,38 @@ discard block |
||
| 246 | 246 | final public function fromJson($data, $callback = null) |
| 247 | 247 | {
|
| 248 | 248 | if (is_scalar($data) && !empty($data)) {
|
| 249 | - $json = json_decode($data); |
|
| 250 | - } else throw new Exception("json is not string with json data");
|
|
| 251 | - |
|
| 252 | - if ($this->jsonError($json)) {
|
|
| 253 | - if (isset($callback) && is_callable($callback)) {
|
|
| 254 | - call_user_func_array($callback, array($json)); |
|
| 255 | - } else {
|
|
| 256 | - if (isset($callback)) throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 249 | + $json = json_decode($data); |
|
| 250 | + } else throw new Exception("json is not string with json data");
|
|
| 251 | + |
|
| 252 | + if ($this->jsonError($json)) {
|
|
| 253 | + if (isset($callback) && is_callable($callback)) {
|
|
| 254 | + call_user_func_array($callback, array($json)); |
|
| 255 | + } else {
|
|
| 256 | + if (isset($callback)) throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 257 | 257 | foreach ($json as $key => $val) {
|
| 258 | - $this->set($key, $val); |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - } else throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
|
|
| 258 | + $this->set($key, $val); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + } else throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
|
|
| 262 | 262 | |
| 263 | - return $this; |
|
| 263 | + return $this; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | final public function toJson($callback = null) |
| 267 | 267 | {
|
| 268 | 268 | $data = $this->toArray(); |
| 269 | 269 | if (isset($callback) && is_callable($callback)) {
|
| 270 | - $data = call_user_func_array($callback, array($data)); |
|
| 271 | - } else {
|
|
| 272 | - if (isset($callback)) throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 273 | - } |
|
| 270 | + $data = call_user_func_array($callback, array($data)); |
|
| 271 | + } else {
|
|
| 272 | + if (isset($callback)) throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 273 | + } |
|
| 274 | 274 | $json = json_encode($data); |
| 275 | 275 | |
| 276 | - if ($this->jsonError($data)) {
|
|
| 277 | - throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
|
|
| 278 | - } |
|
| 276 | + if ($this->jsonError($data)) {
|
|
| 277 | + throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
|
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - return $json; |
|
| 280 | + return $json; |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | final protected function jsonError($data) |
@@ -491,7 +491,7 @@ discard block |
||
| 491 | 491 | * @return array |
| 492 | 492 | */ |
| 493 | 493 | public function getNoDecodeFields(){
|
| 494 | - return $this->_decodedFields->filter(function($value){
|
|
| 494 | + return $this->_decodedFields->filter(function($value){
|
|
| 495 | 495 | return ($value === true); |
| 496 | 496 | }); |
| 497 | 497 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | final public function escape($value){
|
| 67 | 67 | if(!is_scalar($value)){
|
| 68 | 68 | $value = ''; |
| 69 | - }else{
|
|
| 69 | + } else{
|
|
| 70 | 70 | $value = $this->modx->db->escape($value); |
| 71 | 71 | } |
| 72 | 72 | return $value; |
@@ -94,7 +94,9 @@ discard block |
||
| 94 | 94 | final public function list_log($flush = false) |
| 95 | 95 | {
|
| 96 | 96 | echo '<pre>' . print_r(APIHelpers::sanitarTag($this->log), true) . '</pre>'; |
| 97 | - if ($flush) $this->clearLog(); |
|
| 97 | + if ($flush) {
|
|
| 98 | + $this->clearLog(); |
|
| 99 | + } |
|
| 98 | 100 | return $this; |
| 99 | 101 | } |
| 100 | 102 | |
@@ -118,7 +120,7 @@ discard block |
||
| 118 | 120 | $sync->setCachepath($path); |
| 119 | 121 | $sync->setReport(false); |
| 120 | 122 | $sync->emptyCache(); |
| 121 | - }else {
|
|
| 123 | + } else {
|
|
| 122 | 124 | if(is_scalar($custom)){
|
| 123 | 125 | $custom = array($custom); |
| 124 | 126 | } |
@@ -205,7 +207,9 @@ discard block |
||
| 205 | 207 | } else {
|
| 206 | 208 | if ($this->issetField($key) && is_scalar($this->field[$key])) {
|
| 207 | 209 | $tmp = "`{$key}`='{$this->escape($this->field[$key])}'";
|
| 208 | - } else throw new Exception("{$key} is invalid <pre>" . print_r($this->field[$key], true) . "</pre>");
|
|
| 210 | + } else {
|
|
| 211 | + throw new Exception("{$key} is invalid <pre>" . print_r($this->field[$key], true) . "</pre>");
|
|
| 212 | + } |
|
| 209 | 213 | } |
| 210 | 214 | if (!empty($tmp)) {
|
| 211 | 215 | if ($id == '') {
|
@@ -247,18 +251,24 @@ discard block |
||
| 247 | 251 | {
|
| 248 | 252 | if (is_scalar($data) && !empty($data)) {
|
| 249 | 253 | $json = json_decode($data); |
| 250 | - } else throw new Exception("json is not string with json data");
|
|
| 254 | + } else {
|
|
| 255 | + throw new Exception("json is not string with json data");
|
|
| 256 | + } |
|
| 251 | 257 | |
| 252 | 258 | if ($this->jsonError($json)) {
|
| 253 | 259 | if (isset($callback) && is_callable($callback)) {
|
| 254 | 260 | call_user_func_array($callback, array($json)); |
| 255 | 261 | } else {
|
| 256 | - if (isset($callback)) throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 262 | + if (isset($callback)) {
|
|
| 263 | + throw new Exception("Can't call callback JSON unpack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 264 | + } |
|
| 257 | 265 | foreach ($json as $key => $val) {
|
| 258 | 266 | $this->set($key, $val); |
| 259 | 267 | } |
| 260 | 268 | } |
| 261 | - } else throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
|
|
| 269 | + } else {
|
|
| 270 | + throw new Exception('Error from JSON decode: <pre>' . print_r($data, 1) . '</pre>');
|
|
| 271 | + } |
|
| 262 | 272 | |
| 263 | 273 | return $this; |
| 264 | 274 | } |
@@ -269,7 +279,9 @@ discard block |
||
| 269 | 279 | if (isset($callback) && is_callable($callback)) {
|
| 270 | 280 | $data = call_user_func_array($callback, array($data)); |
| 271 | 281 | } else {
|
| 272 | - if (isset($callback)) throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 282 | + if (isset($callback)) {
|
|
| 283 | + throw new Exception("Can't call callback JSON pre pack <pre>" . print_r($callback, 1) . "</pre>");
|
|
| 284 | + } |
|
| 273 | 285 | } |
| 274 | 286 | $json = json_encode($data); |
| 275 | 287 | |
@@ -68,14 +68,14 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | $result = $this->query($SQL); |
| 70 | 70 | } |
| 71 | - if($result && $this->modx->db->getAffectedRows() >= 0 ){ |
|
| 72 | - if ($this->newDoc && !empty($SQL)) $this->id = $this->modx->db->getInsertId(); |
|
| 73 | - if ($clearCache) $this->clearCache($fire_events); |
|
| 74 | - $result = $this->id; |
|
| 75 | - }else{ |
|
| 76 | - if(!empty($SQL)) $this->log['SqlError'] = $SQL; |
|
| 77 | - $result = false; |
|
| 78 | - } |
|
| 71 | + if($result && $this->modx->db->getAffectedRows() >= 0 ){ |
|
| 72 | + if ($this->newDoc && !empty($SQL)) $this->id = $this->modx->db->getInsertId(); |
|
| 73 | + if ($clearCache) $this->clearCache($fire_events); |
|
| 74 | + $result = $this->id; |
|
| 75 | + }else{ |
|
| 76 | + if(!empty($SQL)) $this->log['SqlError'] = $SQL; |
|
| 77 | + $result = false; |
|
| 78 | + } |
|
| 79 | 79 | return $result; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | { |
| 84 | 84 | $_ids = $this->cleanIDs($ids, ','); |
| 85 | 85 | if (is_array($_ids) && $_ids != array()) { |
| 86 | - $id = $this->sanitarIn($_ids); |
|
| 86 | + $id = $this->sanitarIn($_ids); |
|
| 87 | 87 | if(!empty($id)){ |
| 88 | - $this->query("DELETE from {$this->makeTable($this->table)} where `" . $this->pkName . "` IN ({$id})"); |
|
| 89 | - } |
|
| 88 | + $this->query("DELETE from {$this->makeTable($this->table)} where `" . $this->pkName . "` IN ({$id})"); |
|
| 89 | + } |
|
| 90 | 90 | $this->clearCache($fire_events); |
| 91 | - } else throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre>'); |
|
| 91 | + } else throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre>'); |
|
| 92 | 92 | return $this; |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | \ No newline at end of file |
@@ -6,13 +6,13 @@ discard block |
||
| 6 | 6 | protected $table = null; |
| 7 | 7 | protected $generateField = false; |
| 8 | 8 | |
| 9 | - public function tableName(){ |
|
| 9 | + public function tableName() { |
|
| 10 | 10 | return $this->table; |
| 11 | 11 | } |
| 12 | 12 | public function __construct($modx, $debug = false) |
| 13 | 13 | { |
| 14 | 14 | parent::__construct($modx, $debug); |
| 15 | - if(empty($this->default_field)){ |
|
| 15 | + if (empty($this->default_field)) { |
|
| 16 | 16 | $data = $this->modx->db->getTableMetaData($this->makeTable($this->table)); |
| 17 | 17 | foreach ($data as $item) { |
| 18 | 18 | if (empty($this->pkName) && $item['Key'] == 'PRI') { |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | $this->markAllEncode(); |
| 36 | 36 | $this->field = array(); |
| 37 | 37 | $this->set = array(); |
| 38 | - $result = $this->query("SELECT * from {$this->makeTable($this->table)} where `" . $this->pkName . "`='" . $this->escape($id)."'"); |
|
| 38 | + $result = $this->query("SELECT * from {$this->makeTable($this->table)} where `" . $this->pkName . "`='" . $this->escape($id) . "'"); |
|
| 39 | 39 | $this->fromArray($this->modx->db->getRow($result)); |
| 40 | 40 | $this->id = $this->eraseField($this->pkName); |
| 41 | - if(is_bool($this->id) && $this->id === false){ |
|
| 41 | + if (is_bool($this->id) && $this->id === false) { |
|
| 42 | 42 | $this->id = null; |
| 43 | - }else{ |
|
| 43 | + } else { |
|
| 44 | 44 | $this->decodeFields(); |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | if ($this->newDoc && $this->get($key) === null && $this->get($key) !== $value) { |
| 56 | 56 | $this->set($key, $value); |
| 57 | 57 | } |
| 58 | - if((!$this->generateField || isset($fld[$key])) && $this->get($key) !== null){ |
|
| 58 | + if ((!$this->generateField || isset($fld[$key])) && $this->get($key) !== null) { |
|
| 59 | 59 | $this->Uset($key); |
| 60 | 60 | } |
| 61 | 61 | unset($fld[$key]); |
@@ -68,12 +68,12 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | $result = $this->query($SQL); |
| 70 | 70 | } |
| 71 | - if($result && $this->modx->db->getAffectedRows() >= 0 ){ |
|
| 71 | + if ($result && $this->modx->db->getAffectedRows() >= 0) { |
|
| 72 | 72 | if ($this->newDoc && !empty($SQL)) $this->id = $this->modx->db->getInsertId(); |
| 73 | 73 | if ($clearCache) $this->clearCache($fire_events); |
| 74 | 74 | $result = $this->id; |
| 75 | - }else{ |
|
| 76 | - if(!empty($SQL)) $this->log['SqlError'] = $SQL; |
|
| 75 | + } else { |
|
| 76 | + if (!empty($SQL)) $this->log['SqlError'] = $SQL; |
|
| 77 | 77 | $result = false; |
| 78 | 78 | } |
| 79 | 79 | return $result; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $_ids = $this->cleanIDs($ids, ','); |
| 85 | 85 | if (is_array($_ids) && $_ids != array()) { |
| 86 | 86 | $id = $this->sanitarIn($_ids); |
| 87 | - if(!empty($id)){ |
|
| 87 | + if (!empty($id)) { |
|
| 88 | 88 | $this->query("DELETE from {$this->makeTable($this->table)} where `" . $this->pkName . "` IN ({$id})"); |
| 89 | 89 | } |
| 90 | 90 | $this->clearCache($fire_events); |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | $this->id = $this->eraseField($this->pkName); |
| 41 | 41 | if(is_bool($this->id) && $this->id === false){ |
| 42 | 42 | $this->id = null; |
| 43 | - }else{ |
|
| 43 | + } else{ |
|
| 44 | 44 | $this->decodeFields(); |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -69,11 +69,17 @@ discard block |
||
| 69 | 69 | $result = $this->query($SQL); |
| 70 | 70 | } |
| 71 | 71 | if($result && $this->modx->db->getAffectedRows() >= 0 ){ |
| 72 | - if ($this->newDoc && !empty($SQL)) $this->id = $this->modx->db->getInsertId(); |
|
| 73 | - if ($clearCache) $this->clearCache($fire_events); |
|
| 72 | + if ($this->newDoc && !empty($SQL)) {
|
|
| 73 | + $this->id = $this->modx->db->getInsertId(); |
|
| 74 | + } |
|
| 75 | + if ($clearCache) {
|
|
| 76 | + $this->clearCache($fire_events); |
|
| 77 | + } |
|
| 74 | 78 | $result = $this->id; |
| 75 | - }else{ |
|
| 76 | - if(!empty($SQL)) $this->log['SqlError'] = $SQL; |
|
| 79 | + } else{ |
|
| 80 | + if(!empty($SQL)) {
|
|
| 81 | + $this->log['SqlError'] = $SQL; |
|
| 82 | + } |
|
| 77 | 83 | $result = false; |
| 78 | 84 | } |
| 79 | 85 | return $result; |
@@ -88,7 +94,9 @@ discard block |
||
| 88 | 94 | $this->query("DELETE from {$this->makeTable($this->table)} where `" . $this->pkName . "` IN ({$id})"); |
| 89 | 95 | } |
| 90 | 96 | $this->clearCache($fire_events); |
| 91 | - } else throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre>'); |
|
| 97 | + } else {
|
|
| 98 | + throw new Exception('Invalid IDs list for delete: <pre>' . print_r($ids, 1) . '</pre>');
|
|
| 99 | + } |
|
| 92 | 100 | return $this; |
| 93 | 101 | } |
| 94 | 102 | } |
| 95 | 103 | \ No newline at end of file |
@@ -13,382 +13,382 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class Video |
| 15 | 15 | {
|
| 16 | - /** Ссылка на ролик */ |
|
| 17 | - protected $link; |
|
| 18 | - |
|
| 19 | - /** Распарсенные части ссылки */ |
|
| 20 | - protected $link_parts; |
|
| 21 | - |
|
| 22 | - /** Видеохостинг */ |
|
| 23 | - protected $hosting; |
|
| 24 | - |
|
| 25 | - /** Идентификатор видео */ |
|
| 26 | - protected $id; |
|
| 27 | - |
|
| 28 | - /** Картинка */ |
|
| 29 | - protected $image; |
|
| 30 | - |
|
| 31 | - /** Название видео */ |
|
| 32 | - protected $title; |
|
| 33 | - |
|
| 34 | - /** Видео */ |
|
| 35 | - protected $video; |
|
| 36 | - |
|
| 37 | - protected $width = 420; |
|
| 38 | - protected $height = 315; |
|
| 39 | - protected $autoplay = false; |
|
| 40 | - |
|
| 41 | - public $scheme = 'https'; |
|
| 42 | - |
|
| 43 | - const YOUTUBE = 'youtube'; |
|
| 44 | - const VIMEO = 'vimeo'; |
|
| 45 | - const RUTUBE = 'rutube'; |
|
| 46 | - |
|
| 47 | - /** Регулярки для определения видеохостинга и идентификатора ролика */ |
|
| 48 | - protected $regexp = array( |
|
| 49 | - self::YOUTUBE => array( //Не используются |
|
| 50 | - '/[http|https]+:\/\/(?:www\.|)youtube\.com\/watch\?(?:.*)?v=([a-zA-Z0-9_\-]+)/i', |
|
| 51 | - '/[http|https]+:\/\/(?:www\.|)youtube\.com\/embed\/([a-zA-Z0-9_\-]+)/i', |
|
| 52 | - '/[http|https]+:\/\/(?:www\.|)youtu\.be\/([a-zA-Z0-9_\-]+)/i' |
|
| 53 | - ), |
|
| 54 | - self::VIMEO => array( //Не используются |
|
| 55 | - '/[http|https]+:\/\/(?:www\.|)vimeo\.com\/([a-zA-Z0-9_\-]+)(&.+)?/i', |
|
| 56 | - '/[http|https]+:\/\/player\.vimeo\.com\/video\/([a-zA-Z0-9_\-]+)(&.+)?/i' |
|
| 57 | - ), |
|
| 58 | - self::RUTUBE => array( |
|
| 59 | - '/[http|https]+:\/\/(?:www\.|)rutube\.ru\/video\/embed\/([a-zA-Z0-9_\-]+)/i', |
|
| 60 | - '/[http|https]+:\/\/(?:www\.|)rutube\.ru\/tracks\/([a-zA-Z0-9_\-]+)(&.+)?/i' |
|
| 61 | - ) |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - /** Ссылка на RUtube без идентификатора в адресе */ |
|
| 65 | - protected $regexp_rutube_extra = '/[http|https]+:\/\/(?:www\.|)rutube\.ru\/video\/([a-zA-Z0-9_\-]+)\//i'; |
|
| 66 | - |
|
| 67 | - /** Варианты ссылок, которые поддерживаются */ |
|
| 68 | - protected static $test = array( |
|
| 69 | - 'http://youtube.com/watch?v=ShPq2Dmy6X8', |
|
| 70 | - 'http://www.youtube.com/watch?v=6dwqZw0j_jY&feature=youtu.be', |
|
| 71 | - 'http://www.youtube.com/watch?v=cKZDdG9FTKY&feature=channel', |
|
| 72 | - 'www.youtube.com/watch?v=yZ-K7nCVnBI&playnext_from=TL&videos=osPknwzXEas&feature=sub', |
|
| 73 | - 'http://www.youtube.com/embed/ShPq2Dmy6X8?rel=0', |
|
| 74 | - 'http://youtu.be/ShPq2Dmy6X8', |
|
| 75 | - 'youtu.be/6dwqZw0j_jY', |
|
| 76 | - 'http://www.youtu.be/afa-5HQHiAs', |
|
| 77 | - |
|
| 78 | - 'vimeo.com/55028438', |
|
| 79 | - 'http://player.vimeo.com/video/55028438?title=0&byline=0&portrait=0&badge=0&color=e1a931', |
|
| 80 | - |
|
| 81 | - 'http://rutube.ru/video/6fd81c1c212c002673280850a1c56415/#.UMQYln9yTWQ', |
|
| 82 | - 'http://rutube.ru/video/dec0a58c8cb4d226abc7b1030bbb63b9/?ref=top', |
|
| 83 | - 'rutube.ru/tracks/6032725.html', |
|
| 84 | - 'http://www.rutube.ru/video/embed/6032725', |
|
| 85 | - ); |
|
| 86 | - |
|
| 87 | - protected $info = false; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param $link ссылка на видео |
|
| 91 | - * @param $autostart сразу определить превью и клип |
|
| 92 | - */ |
|
| 93 | - public function __construct($link = null, $autostart = true, $info = false) |
|
| 94 | - {
|
|
| 95 | - if ($link) {
|
|
| 96 | - $this->setLink($link); |
|
| 97 | - $this->setInfo($info); |
|
| 98 | - if ($autostart) {
|
|
| 99 | - $this->process(); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - public function getScheme(){
|
|
| 104 | - switch($this->scheme){
|
|
| 105 | - case 'http': |
|
| 106 | - $out = 'http://'; |
|
| 107 | - break; |
|
| 108 | - case 'https': |
|
| 109 | - $out = 'https://'; |
|
| 110 | - break; |
|
| 111 | - default: |
|
| 112 | - $out = '//'; |
|
| 113 | - break; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - return $out; |
|
| 117 | - } |
|
| 118 | - public function setInfo($info){
|
|
| 119 | - $this->info = (bool)$info; |
|
| 120 | - } |
|
| 121 | - public function getInfo(){
|
|
| 122 | - return $this->info; |
|
| 123 | - } |
|
| 124 | - /** Видеохостинг */ |
|
| 125 | - public function getHosting() |
|
| 126 | - {
|
|
| 127 | - return $this->hosting; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** Идентификатор видео */ |
|
| 131 | - public function getId() |
|
| 132 | - {
|
|
| 133 | - return $this->id; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** Ссылка на превью */ |
|
| 137 | - public function getImage() |
|
| 138 | - {
|
|
| 139 | - return $this->getScheme().$this->image; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** Ссылка на видео */ |
|
| 143 | - public function getVideo($autoplay = false) |
|
| 144 | - {
|
|
| 145 | - $url = $this->video; |
|
| 146 | - if($autoplay){
|
|
| 147 | - $url .= '&autoplay=1'; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $this->getScheme().$url; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** Название видео */ |
|
| 154 | - public function getTitle() |
|
| 155 | - {
|
|
| 156 | - return $this->title; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** Задать ссылку на видео */ |
|
| 160 | - public function setLink($link) |
|
| 161 | - {
|
|
| 162 | - $this->link = $link; |
|
| 163 | - |
|
| 164 | - return $this; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** Обработка ссылки. Возвращает идентификатор видеохостинга или false */ |
|
| 168 | - public function process($link = null, $info = null) |
|
| 169 | - {
|
|
| 170 | - if(!empty($link)) $this->setLink($link); |
|
| 171 | - if(!empty($info)) $this->setInfo($info); |
|
| 172 | - |
|
| 173 | - if ($this->cleanLink()) {
|
|
| 174 | - if ($this->maybeYoutube()) {
|
|
| 175 | - return self::YOUTUBE; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - if ($this->maybeVimeo()) {
|
|
| 179 | - return self::VIMEO; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if ($this->maybeRutube()) {
|
|
| 183 | - return self::RUTUBE; |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return false; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** Скачать превью. Если не указать имя файла для записи - функция вернет содержимое файла */ |
|
| 191 | - public function fetchImage($filename = null) |
|
| 192 | - {
|
|
| 193 | - if (!$url = $this->getImage()) {
|
|
| 194 | - return false; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - if (!$res = $this->fetchPage($url)) {
|
|
| 198 | - return false; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return $filename |
|
| 202 | - ? file_put_contents($filename, $res) |
|
| 203 | - : $res; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** Проверка и подготовка ссылки и частей */ |
|
| 207 | - protected function cleanLink() |
|
| 208 | - {
|
|
| 209 | - if (!preg_match('/^(http|https)\:\/\//i', $this->link)) {
|
|
| 210 | - $this->link = 'http://' . $this->link; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - if (!$this->link_parts = parse_url($this->link)) {
|
|
| 214 | - return false; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - return true; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** Проверка YOUTUBE */ |
|
| 221 | - protected function maybeYoutube() |
|
| 222 | - {
|
|
| 223 | - $h = str_replace('www.', '', $this->link_parts['host']);
|
|
| 224 | - $p = isset($this->link_parts['path']) ? $this->link_parts['path'] : false; |
|
| 225 | - |
|
| 226 | - if ('youtube.com' == $h) {
|
|
| 227 | - parse_str($this->link_parts['query'], $q); |
|
| 228 | - |
|
| 229 | - if ('/watch' == $p && !empty($q['v'])) {
|
|
| 230 | - return $this->foundYoutube($q['v']); |
|
| 231 | - } |
|
| 232 | - if (0 === strpos($p, '/embed/')) {
|
|
| 233 | - return $this->foundYoutube(str_replace('/embed/', '', $p));
|
|
| 234 | - } |
|
| 235 | - } elseif ('youtu.be' == $h) {
|
|
| 236 | - return $this->foundYoutube(trim($p, '/')); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return false; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** Проверка VIMEO */ |
|
| 243 | - protected function maybeVimeo() |
|
| 244 | - {
|
|
| 245 | - $h = str_replace('www.', '', $this->link_parts['host']);
|
|
| 246 | - $p = isset($this->link_parts['path']) ? $this->link_parts['path'] : false; |
|
| 247 | - |
|
| 248 | - if ('vimeo.com' == $h) {
|
|
| 249 | - return $this->foundVimeo(trim($p, '/')); |
|
| 250 | - } elseif ('player.vimeo.com' == $h && 0 === strpos($p, '/video/')) {
|
|
| 251 | - return $this->foundVimeo(str_replace('/video/', '', $p));
|
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - return false; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** Проверка RUTUBE */ |
|
| 258 | - protected function maybeRutube($html = null) |
|
| 259 | - {
|
|
| 260 | - $link = $html ?: $this->link; |
|
| 261 | - |
|
| 262 | - foreach ($this->regexp[self::RUTUBE] as $regexp) {
|
|
| 263 | - if (preg_match($regexp, $link, $matches)) {
|
|
| 264 | - return $this->foundRutube($matches[1]); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - // Проверка на особенную ссылку RUtube`a |
|
| 269 | - if (is_null($html) && preg_match($this->regexp_rutube_extra, $this->link, $matches)) {
|
|
| 270 | - $html = $this->fetchPage($matches[0]); |
|
| 271 | - if ($r = $this->maybeRutube($html)) {
|
|
| 272 | - return $r; |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - return false; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** Обработка YOUTUBE */ |
|
| 280 | - protected function foundYoutube($id) |
|
| 281 | - {
|
|
| 282 | - if (empty($id) || strlen($id) != 11) {
|
|
| 283 | - return false; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $this->hosting = self::YOUTUBE; |
|
| 287 | - $this->id = $id; |
|
| 288 | - $this->image = 'img.youtube.com/vi/' . $id . '/0.jpg'; |
|
| 289 | - /** @see https://developers.google.com/youtube/player_parameters */ |
|
| 290 | - $this->video = 'www.youtube.com/embed/' . $id.'?showinfo=0&modestbranding=1&rel=0'; |
|
| 291 | - |
|
| 292 | - if ($this->info) {
|
|
| 293 | - $this->getYoutubeInfo($id); |
|
| 294 | - } |
|
| 295 | - return true; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** Обработка VIMEO */ |
|
| 299 | - protected function foundVimeo($id) |
|
| 300 | - {
|
|
| 301 | - if (empty($id) || !is_numeric($id)) {
|
|
| 302 | - return false; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - $this->hosting = self::VIMEO; |
|
| 306 | - $this->id = $id; |
|
| 307 | - $this->video = 'player.vimeo.com/video/' . $id.'?'; |
|
| 308 | - |
|
| 309 | - if($this->info) {
|
|
| 310 | - $this->getVimeoInfo($id); |
|
| 311 | - } |
|
| 312 | - return true; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** Обработка RUTUBE */ |
|
| 316 | - protected function foundRutube($id) |
|
| 317 | - {
|
|
| 318 | - $this->hosting = self::RUTUBE; |
|
| 319 | - $this->id = $id; |
|
| 320 | - $this->video = 'rutube.ru/video/embed/' . $id.'?'; |
|
| 321 | - |
|
| 322 | - if($this->info) {
|
|
| 323 | - $this->getRutubeInfo($id); |
|
| 324 | - } |
|
| 325 | - return true; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** Парсинг XML от RUTUBE и определение превьюхи */ |
|
| 329 | - protected function getRutubeInfo($id) |
|
| 330 | - {
|
|
| 331 | - if (@$xml = simplexml_load_file("http://rutube.ru/cgi-bin/xmlapi.cgi?rt_mode=movie&rt_movie_id=" . $id . "&utf=1")) {
|
|
| 332 | - $this->title = (string)$xml->title; |
|
| 333 | - $this->image = (string)$xml->thumbnail_url; |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - /** Парсинг XML от VIMEO и определение превьюхи */ |
|
| 338 | - protected function getVimeoInfo($id) |
|
| 339 | - {
|
|
| 340 | - if (@$xml = simplexml_load_file('http://vimeo.com/api/v2/video/' . $id . '.xml')) {
|
|
| 341 | - $this->title = (string)$xml->video->title; |
|
| 342 | - $this->image = (string)$xml->video->thumbnail_large ? : $xml->video->thumbnail_medium; |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** Получение названия ролика */ |
|
| 347 | - protected function getYoutubeInfo($id) |
|
| 348 | - {
|
|
| 349 | - if (@$xml = simplexml_load_file('http://gdata.youtube.com/feeds/api/videos/' . $id)) {
|
|
| 350 | - $this->title = (string)$xml->title; |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - /** Скачивание страницы с помощью CURL */ |
|
| 355 | - protected function fetchPage($url) |
|
| 356 | - {
|
|
| 357 | - $ch = curl_init(); |
|
| 358 | - curl_setopt($ch, CURLOPT_URL, $url); |
|
| 359 | - curl_setopt($ch, CURLOPT_FAILONERROR, true); |
|
| 360 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 361 | - curl_setopt($ch, CURLOPT_TIMEOUT, 3); |
|
| 362 | - |
|
| 363 | - return curl_exec($ch); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - public function getEmbed($options){
|
|
| 367 | - $autoplay = isset($options["autoplay"]) ? $options["autoplay"] : $this->autoplay; |
|
| 368 | - $width = isset($options["width"]) ? (int)$options["width"] : $this->width; |
|
| 369 | - $height = isset($options["height"]) ? (int)$options["height"] : $this->height; |
|
| 370 | - $class = isset($options['class']) ? $options['class'] : ''; |
|
| 371 | - |
|
| 372 | - $url = $this->getVideo($autoplay); |
|
| 373 | - if(!empty($class)){
|
|
| 374 | - $class = ' class="'.$class.'"'; |
|
| 375 | - } |
|
| 376 | - return '<iframe src="'.$url.'" width="'.$width.'" height="'.$height.'" frameborder="0" allowfullscreen'.$class.'></iframe>'; |
|
| 377 | - } |
|
| 378 | - /** Прогоняем тест по видам URL */ |
|
| 379 | - public static function RunTest($links = null) |
|
| 380 | - {
|
|
| 381 | - if (!is_array($links)) {
|
|
| 382 | - $links = static::$test; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - foreach ($links as $link) {
|
|
| 386 | - $v = new static($link); |
|
| 387 | - echo "<h1>$link</h1>\n" |
|
| 388 | - . "<h3>" . $v->getHosting() . "</h3>" |
|
| 389 | - . "<b>Видео:</b> " . $v->getVideo() . "<br />\n" |
|
| 390 | - . "<b>Название:</b> " . $v->getTitle() . "<br />\n" |
|
| 391 | - . "<b>Картинка:</b> " . $v->getImage() . "<hr />\n"; |
|
| 392 | - } |
|
| 393 | - } |
|
| 16 | + /** Ссылка на ролик */ |
|
| 17 | + protected $link; |
|
| 18 | + |
|
| 19 | + /** Распарсенные части ссылки */ |
|
| 20 | + protected $link_parts; |
|
| 21 | + |
|
| 22 | + /** Видеохостинг */ |
|
| 23 | + protected $hosting; |
|
| 24 | + |
|
| 25 | + /** Идентификатор видео */ |
|
| 26 | + protected $id; |
|
| 27 | + |
|
| 28 | + /** Картинка */ |
|
| 29 | + protected $image; |
|
| 30 | + |
|
| 31 | + /** Название видео */ |
|
| 32 | + protected $title; |
|
| 33 | + |
|
| 34 | + /** Видео */ |
|
| 35 | + protected $video; |
|
| 36 | + |
|
| 37 | + protected $width = 420; |
|
| 38 | + protected $height = 315; |
|
| 39 | + protected $autoplay = false; |
|
| 40 | + |
|
| 41 | + public $scheme = 'https'; |
|
| 42 | + |
|
| 43 | + const YOUTUBE = 'youtube'; |
|
| 44 | + const VIMEO = 'vimeo'; |
|
| 45 | + const RUTUBE = 'rutube'; |
|
| 46 | + |
|
| 47 | + /** Регулярки для определения видеохостинга и идентификатора ролика */ |
|
| 48 | + protected $regexp = array( |
|
| 49 | + self::YOUTUBE => array( //Не используются |
|
| 50 | + '/[http|https]+:\/\/(?:www\.|)youtube\.com\/watch\?(?:.*)?v=([a-zA-Z0-9_\-]+)/i', |
|
| 51 | + '/[http|https]+:\/\/(?:www\.|)youtube\.com\/embed\/([a-zA-Z0-9_\-]+)/i', |
|
| 52 | + '/[http|https]+:\/\/(?:www\.|)youtu\.be\/([a-zA-Z0-9_\-]+)/i' |
|
| 53 | + ), |
|
| 54 | + self::VIMEO => array( //Не используются |
|
| 55 | + '/[http|https]+:\/\/(?:www\.|)vimeo\.com\/([a-zA-Z0-9_\-]+)(&.+)?/i', |
|
| 56 | + '/[http|https]+:\/\/player\.vimeo\.com\/video\/([a-zA-Z0-9_\-]+)(&.+)?/i' |
|
| 57 | + ), |
|
| 58 | + self::RUTUBE => array( |
|
| 59 | + '/[http|https]+:\/\/(?:www\.|)rutube\.ru\/video\/embed\/([a-zA-Z0-9_\-]+)/i', |
|
| 60 | + '/[http|https]+:\/\/(?:www\.|)rutube\.ru\/tracks\/([a-zA-Z0-9_\-]+)(&.+)?/i' |
|
| 61 | + ) |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + /** Ссылка на RUtube без идентификатора в адресе */ |
|
| 65 | + protected $regexp_rutube_extra = '/[http|https]+:\/\/(?:www\.|)rutube\.ru\/video\/([a-zA-Z0-9_\-]+)\//i'; |
|
| 66 | + |
|
| 67 | + /** Варианты ссылок, которые поддерживаются */ |
|
| 68 | + protected static $test = array( |
|
| 69 | + 'http://youtube.com/watch?v=ShPq2Dmy6X8', |
|
| 70 | + 'http://www.youtube.com/watch?v=6dwqZw0j_jY&feature=youtu.be', |
|
| 71 | + 'http://www.youtube.com/watch?v=cKZDdG9FTKY&feature=channel', |
|
| 72 | + 'www.youtube.com/watch?v=yZ-K7nCVnBI&playnext_from=TL&videos=osPknwzXEas&feature=sub', |
|
| 73 | + 'http://www.youtube.com/embed/ShPq2Dmy6X8?rel=0', |
|
| 74 | + 'http://youtu.be/ShPq2Dmy6X8', |
|
| 75 | + 'youtu.be/6dwqZw0j_jY', |
|
| 76 | + 'http://www.youtu.be/afa-5HQHiAs', |
|
| 77 | + |
|
| 78 | + 'vimeo.com/55028438', |
|
| 79 | + 'http://player.vimeo.com/video/55028438?title=0&byline=0&portrait=0&badge=0&color=e1a931', |
|
| 80 | + |
|
| 81 | + 'http://rutube.ru/video/6fd81c1c212c002673280850a1c56415/#.UMQYln9yTWQ', |
|
| 82 | + 'http://rutube.ru/video/dec0a58c8cb4d226abc7b1030bbb63b9/?ref=top', |
|
| 83 | + 'rutube.ru/tracks/6032725.html', |
|
| 84 | + 'http://www.rutube.ru/video/embed/6032725', |
|
| 85 | + ); |
|
| 86 | + |
|
| 87 | + protected $info = false; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param $link ссылка на видео |
|
| 91 | + * @param $autostart сразу определить превью и клип |
|
| 92 | + */ |
|
| 93 | + public function __construct($link = null, $autostart = true, $info = false) |
|
| 94 | + {
|
|
| 95 | + if ($link) {
|
|
| 96 | + $this->setLink($link); |
|
| 97 | + $this->setInfo($info); |
|
| 98 | + if ($autostart) {
|
|
| 99 | + $this->process(); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + public function getScheme(){
|
|
| 104 | + switch($this->scheme){
|
|
| 105 | + case 'http': |
|
| 106 | + $out = 'http://'; |
|
| 107 | + break; |
|
| 108 | + case 'https': |
|
| 109 | + $out = 'https://'; |
|
| 110 | + break; |
|
| 111 | + default: |
|
| 112 | + $out = '//'; |
|
| 113 | + break; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + return $out; |
|
| 117 | + } |
|
| 118 | + public function setInfo($info){
|
|
| 119 | + $this->info = (bool)$info; |
|
| 120 | + } |
|
| 121 | + public function getInfo(){
|
|
| 122 | + return $this->info; |
|
| 123 | + } |
|
| 124 | + /** Видеохостинг */ |
|
| 125 | + public function getHosting() |
|
| 126 | + {
|
|
| 127 | + return $this->hosting; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** Идентификатор видео */ |
|
| 131 | + public function getId() |
|
| 132 | + {
|
|
| 133 | + return $this->id; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** Ссылка на превью */ |
|
| 137 | + public function getImage() |
|
| 138 | + {
|
|
| 139 | + return $this->getScheme().$this->image; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** Ссылка на видео */ |
|
| 143 | + public function getVideo($autoplay = false) |
|
| 144 | + {
|
|
| 145 | + $url = $this->video; |
|
| 146 | + if($autoplay){
|
|
| 147 | + $url .= '&autoplay=1'; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $this->getScheme().$url; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** Название видео */ |
|
| 154 | + public function getTitle() |
|
| 155 | + {
|
|
| 156 | + return $this->title; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** Задать ссылку на видео */ |
|
| 160 | + public function setLink($link) |
|
| 161 | + {
|
|
| 162 | + $this->link = $link; |
|
| 163 | + |
|
| 164 | + return $this; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** Обработка ссылки. Возвращает идентификатор видеохостинга или false */ |
|
| 168 | + public function process($link = null, $info = null) |
|
| 169 | + {
|
|
| 170 | + if(!empty($link)) $this->setLink($link); |
|
| 171 | + if(!empty($info)) $this->setInfo($info); |
|
| 172 | + |
|
| 173 | + if ($this->cleanLink()) {
|
|
| 174 | + if ($this->maybeYoutube()) {
|
|
| 175 | + return self::YOUTUBE; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + if ($this->maybeVimeo()) {
|
|
| 179 | + return self::VIMEO; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if ($this->maybeRutube()) {
|
|
| 183 | + return self::RUTUBE; |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return false; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** Скачать превью. Если не указать имя файла для записи - функция вернет содержимое файла */ |
|
| 191 | + public function fetchImage($filename = null) |
|
| 192 | + {
|
|
| 193 | + if (!$url = $this->getImage()) {
|
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + if (!$res = $this->fetchPage($url)) {
|
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return $filename |
|
| 202 | + ? file_put_contents($filename, $res) |
|
| 203 | + : $res; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** Проверка и подготовка ссылки и частей */ |
|
| 207 | + protected function cleanLink() |
|
| 208 | + {
|
|
| 209 | + if (!preg_match('/^(http|https)\:\/\//i', $this->link)) {
|
|
| 210 | + $this->link = 'http://' . $this->link; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + if (!$this->link_parts = parse_url($this->link)) {
|
|
| 214 | + return false; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + return true; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** Проверка YOUTUBE */ |
|
| 221 | + protected function maybeYoutube() |
|
| 222 | + {
|
|
| 223 | + $h = str_replace('www.', '', $this->link_parts['host']);
|
|
| 224 | + $p = isset($this->link_parts['path']) ? $this->link_parts['path'] : false; |
|
| 225 | + |
|
| 226 | + if ('youtube.com' == $h) {
|
|
| 227 | + parse_str($this->link_parts['query'], $q); |
|
| 228 | + |
|
| 229 | + if ('/watch' == $p && !empty($q['v'])) {
|
|
| 230 | + return $this->foundYoutube($q['v']); |
|
| 231 | + } |
|
| 232 | + if (0 === strpos($p, '/embed/')) {
|
|
| 233 | + return $this->foundYoutube(str_replace('/embed/', '', $p));
|
|
| 234 | + } |
|
| 235 | + } elseif ('youtu.be' == $h) {
|
|
| 236 | + return $this->foundYoutube(trim($p, '/')); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return false; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** Проверка VIMEO */ |
|
| 243 | + protected function maybeVimeo() |
|
| 244 | + {
|
|
| 245 | + $h = str_replace('www.', '', $this->link_parts['host']);
|
|
| 246 | + $p = isset($this->link_parts['path']) ? $this->link_parts['path'] : false; |
|
| 247 | + |
|
| 248 | + if ('vimeo.com' == $h) {
|
|
| 249 | + return $this->foundVimeo(trim($p, '/')); |
|
| 250 | + } elseif ('player.vimeo.com' == $h && 0 === strpos($p, '/video/')) {
|
|
| 251 | + return $this->foundVimeo(str_replace('/video/', '', $p));
|
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + return false; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** Проверка RUTUBE */ |
|
| 258 | + protected function maybeRutube($html = null) |
|
| 259 | + {
|
|
| 260 | + $link = $html ?: $this->link; |
|
| 261 | + |
|
| 262 | + foreach ($this->regexp[self::RUTUBE] as $regexp) {
|
|
| 263 | + if (preg_match($regexp, $link, $matches)) {
|
|
| 264 | + return $this->foundRutube($matches[1]); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + // Проверка на особенную ссылку RUtube`a |
|
| 269 | + if (is_null($html) && preg_match($this->regexp_rutube_extra, $this->link, $matches)) {
|
|
| 270 | + $html = $this->fetchPage($matches[0]); |
|
| 271 | + if ($r = $this->maybeRutube($html)) {
|
|
| 272 | + return $r; |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + return false; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** Обработка YOUTUBE */ |
|
| 280 | + protected function foundYoutube($id) |
|
| 281 | + {
|
|
| 282 | + if (empty($id) || strlen($id) != 11) {
|
|
| 283 | + return false; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $this->hosting = self::YOUTUBE; |
|
| 287 | + $this->id = $id; |
|
| 288 | + $this->image = 'img.youtube.com/vi/' . $id . '/0.jpg'; |
|
| 289 | + /** @see https://developers.google.com/youtube/player_parameters */ |
|
| 290 | + $this->video = 'www.youtube.com/embed/' . $id.'?showinfo=0&modestbranding=1&rel=0'; |
|
| 291 | + |
|
| 292 | + if ($this->info) {
|
|
| 293 | + $this->getYoutubeInfo($id); |
|
| 294 | + } |
|
| 295 | + return true; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** Обработка VIMEO */ |
|
| 299 | + protected function foundVimeo($id) |
|
| 300 | + {
|
|
| 301 | + if (empty($id) || !is_numeric($id)) {
|
|
| 302 | + return false; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + $this->hosting = self::VIMEO; |
|
| 306 | + $this->id = $id; |
|
| 307 | + $this->video = 'player.vimeo.com/video/' . $id.'?'; |
|
| 308 | + |
|
| 309 | + if($this->info) {
|
|
| 310 | + $this->getVimeoInfo($id); |
|
| 311 | + } |
|
| 312 | + return true; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** Обработка RUTUBE */ |
|
| 316 | + protected function foundRutube($id) |
|
| 317 | + {
|
|
| 318 | + $this->hosting = self::RUTUBE; |
|
| 319 | + $this->id = $id; |
|
| 320 | + $this->video = 'rutube.ru/video/embed/' . $id.'?'; |
|
| 321 | + |
|
| 322 | + if($this->info) {
|
|
| 323 | + $this->getRutubeInfo($id); |
|
| 324 | + } |
|
| 325 | + return true; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** Парсинг XML от RUTUBE и определение превьюхи */ |
|
| 329 | + protected function getRutubeInfo($id) |
|
| 330 | + {
|
|
| 331 | + if (@$xml = simplexml_load_file("http://rutube.ru/cgi-bin/xmlapi.cgi?rt_mode=movie&rt_movie_id=" . $id . "&utf=1")) {
|
|
| 332 | + $this->title = (string)$xml->title; |
|
| 333 | + $this->image = (string)$xml->thumbnail_url; |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + /** Парсинг XML от VIMEO и определение превьюхи */ |
|
| 338 | + protected function getVimeoInfo($id) |
|
| 339 | + {
|
|
| 340 | + if (@$xml = simplexml_load_file('http://vimeo.com/api/v2/video/' . $id . '.xml')) {
|
|
| 341 | + $this->title = (string)$xml->video->title; |
|
| 342 | + $this->image = (string)$xml->video->thumbnail_large ? : $xml->video->thumbnail_medium; |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** Получение названия ролика */ |
|
| 347 | + protected function getYoutubeInfo($id) |
|
| 348 | + {
|
|
| 349 | + if (@$xml = simplexml_load_file('http://gdata.youtube.com/feeds/api/videos/' . $id)) {
|
|
| 350 | + $this->title = (string)$xml->title; |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + /** Скачивание страницы с помощью CURL */ |
|
| 355 | + protected function fetchPage($url) |
|
| 356 | + {
|
|
| 357 | + $ch = curl_init(); |
|
| 358 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
| 359 | + curl_setopt($ch, CURLOPT_FAILONERROR, true); |
|
| 360 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 361 | + curl_setopt($ch, CURLOPT_TIMEOUT, 3); |
|
| 362 | + |
|
| 363 | + return curl_exec($ch); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + public function getEmbed($options){
|
|
| 367 | + $autoplay = isset($options["autoplay"]) ? $options["autoplay"] : $this->autoplay; |
|
| 368 | + $width = isset($options["width"]) ? (int)$options["width"] : $this->width; |
|
| 369 | + $height = isset($options["height"]) ? (int)$options["height"] : $this->height; |
|
| 370 | + $class = isset($options['class']) ? $options['class'] : ''; |
|
| 371 | + |
|
| 372 | + $url = $this->getVideo($autoplay); |
|
| 373 | + if(!empty($class)){
|
|
| 374 | + $class = ' class="'.$class.'"'; |
|
| 375 | + } |
|
| 376 | + return '<iframe src="'.$url.'" width="'.$width.'" height="'.$height.'" frameborder="0" allowfullscreen'.$class.'></iframe>'; |
|
| 377 | + } |
|
| 378 | + /** Прогоняем тест по видам URL */ |
|
| 379 | + public static function RunTest($links = null) |
|
| 380 | + {
|
|
| 381 | + if (!is_array($links)) {
|
|
| 382 | + $links = static::$test; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + foreach ($links as $link) {
|
|
| 386 | + $v = new static($link); |
|
| 387 | + echo "<h1>$link</h1>\n" |
|
| 388 | + . "<h3>" . $v->getHosting() . "</h3>" |
|
| 389 | + . "<b>Видео:</b> " . $v->getVideo() . "<br />\n" |
|
| 390 | + . "<b>Название:</b> " . $v->getTitle() . "<br />\n" |
|
| 391 | + . "<b>Картинка:</b> " . $v->getImage() . "<hr />\n"; |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | 394 | } |
| 395 | 395 | \ No newline at end of file |
@@ -12,9 +12,9 @@ discard block |
||
| 12 | 12 | class Actions{
|
| 13 | 13 | protected $modx = null; |
| 14 | 14 | public $userObj = null; |
| 15 | - /** |
|
| 16 | - * @var DLCollection |
|
| 17 | - */ |
|
| 15 | + /** |
|
| 16 | + * @var DLCollection |
|
| 17 | + */ |
|
| 18 | 18 | public $url; |
| 19 | 19 | protected static $lang = null; |
| 20 | 20 | protected static $langDic = array(); |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | protected static $instance; |
| 25 | 25 | |
| 26 | - protected $config = array(); |
|
| 26 | + protected $config = array(); |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * gets the instance via lazy initialization (created on first usage) |
@@ -50,15 +50,15 @@ discard block |
||
| 50 | 50 | private function __construct(DocumentParser $modx, $userClass, $debug) |
| 51 | 51 | {
|
| 52 | 52 | $this->modx = $modx; |
| 53 | - $this->userObj = new $userClass($this->modx, $debug); |
|
| 54 | - $this->url = new DLCollection($this->modx); |
|
| 53 | + $this->userObj = new $userClass($this->modx, $debug); |
|
| 54 | + $this->url = new DLCollection($this->modx); |
|
| 55 | 55 | |
| 56 | - $site_url = $this->modx->getConfig('site_url');
|
|
| 57 | - $site_start = $this->modx->getConfig('site_start', 1);
|
|
| 58 | - $error_page = $this->modx->getConfig('error_page', $site_start);
|
|
| 59 | - $unauthorized_page = $this->modx->getConfig('unauthorized_page', $error_page);
|
|
| 56 | + $site_url = $this->modx->getConfig('site_url');
|
|
| 57 | + $site_start = $this->modx->getConfig('site_start', 1);
|
|
| 58 | + $error_page = $this->modx->getConfig('error_page', $site_start);
|
|
| 59 | + $unauthorized_page = $this->modx->getConfig('unauthorized_page', $error_page);
|
|
| 60 | 60 | |
| 61 | - $this->config = compact('site_url', 'site_start', 'error_page', 'unauthorized_page');
|
|
| 61 | + $this->config = compact('site_url', 'site_start', 'error_page', 'unauthorized_page');
|
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -85,48 +85,48 @@ discard block |
||
| 85 | 85 | * Сброс авторизации и обновление страницы |
| 86 | 86 | */ |
| 87 | 87 | public function logout($params){
|
| 88 | - $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
|
| 89 | - if(is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])){
|
|
| 90 | - $type = 'web'; |
|
| 91 | - $userID = $this->UserID(compact('type'));
|
|
| 92 | - if($userID){
|
|
| 93 | - $this->userObj->edit($userID); |
|
| 94 | - if($this->userObj->getID()){
|
|
| 95 | - $this->modx->invokeEvent("OnBeforeWebLogout", array(
|
|
| 96 | - "userid" => $this->userObj->getID(), |
|
| 97 | - "username" => $this->userObj->get('username')
|
|
| 98 | - )); |
|
| 99 | - } |
|
| 100 | - $this->userObj->logOut(); |
|
| 101 | - if($this->userObj->getID()){
|
|
| 102 | - $this->modx->invokeEvent("OnWebLogout", array(
|
|
| 103 | - "userid" => $this->userObj->getID(), |
|
| 104 | - "username" => $this->userObj->get('username')
|
|
| 105 | - )); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $go = APIHelpers::getkey($params, 'url', ''); |
|
| 109 | - if(empty($go)){
|
|
| 110 | - $go = str_replace( |
|
| 111 | - array("?".$LogoutName, "&".$LogoutName),
|
|
| 112 | - array("", ""),
|
|
| 113 | - $_SERVER['REQUEST_URI'] |
|
| 114 | - ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $start = $this->makeUrl($this->config['site_start']); |
|
| 118 | - if($start == $go){
|
|
| 119 | - $go = $this->config['site_url']; |
|
| 120 | - }else{
|
|
| 121 | - $go = $this->config['site_url'].ltrim($go, '/'); |
|
| 122 | - } |
|
| 123 | - $this->moveTo(array('url' => $go));
|
|
| 124 | - }else{
|
|
| 125 | - //Если юзер не авторизован, то показываем ему 404 ошибку |
|
| 126 | - $this->modx->sendErrorPage(); |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - return true; |
|
| 88 | + $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
|
| 89 | + if(is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])){
|
|
| 90 | + $type = 'web'; |
|
| 91 | + $userID = $this->UserID(compact('type'));
|
|
| 92 | + if($userID){
|
|
| 93 | + $this->userObj->edit($userID); |
|
| 94 | + if($this->userObj->getID()){
|
|
| 95 | + $this->modx->invokeEvent("OnBeforeWebLogout", array(
|
|
| 96 | + "userid" => $this->userObj->getID(), |
|
| 97 | + "username" => $this->userObj->get('username')
|
|
| 98 | + )); |
|
| 99 | + } |
|
| 100 | + $this->userObj->logOut(); |
|
| 101 | + if($this->userObj->getID()){
|
|
| 102 | + $this->modx->invokeEvent("OnWebLogout", array(
|
|
| 103 | + "userid" => $this->userObj->getID(), |
|
| 104 | + "username" => $this->userObj->get('username')
|
|
| 105 | + )); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $go = APIHelpers::getkey($params, 'url', ''); |
|
| 109 | + if(empty($go)){
|
|
| 110 | + $go = str_replace( |
|
| 111 | + array("?".$LogoutName, "&".$LogoutName),
|
|
| 112 | + array("", ""),
|
|
| 113 | + $_SERVER['REQUEST_URI'] |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $start = $this->makeUrl($this->config['site_start']); |
|
| 118 | + if($start == $go){
|
|
| 119 | + $go = $this->config['site_url']; |
|
| 120 | + }else{
|
|
| 121 | + $go = $this->config['site_url'].ltrim($go, '/'); |
|
| 122 | + } |
|
| 123 | + $this->moveTo(array('url' => $go));
|
|
| 124 | + }else{
|
|
| 125 | + //Если юзер не авторизован, то показываем ему 404 ошибку |
|
| 126 | + $this->modx->sendErrorPage(); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + return true; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -134,14 +134,14 @@ discard block |
||
| 134 | 134 | * @return string |
| 135 | 135 | */ |
| 136 | 136 | public function logoutUrl($params){
|
| 137 | - $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
|
| 138 | - $request = parse_url($_SERVER['REQUEST_URI']); |
|
| 137 | + $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
|
| 138 | + $request = parse_url($_SERVER['REQUEST_URI']); |
|
| 139 | 139 | |
| 140 | - //Во избежании XSS мы не сохраняем весь REQUEST_URI, а берем только path |
|
| 141 | - /*$query = (!empty($request['query'])) ? $request['query'].'&' : '';*/ |
|
| 142 | - $query = '?'.$LogoutName; |
|
| 140 | + //Во избежании XSS мы не сохраняем весь REQUEST_URI, а берем только path |
|
| 141 | + /*$query = (!empty($request['query'])) ? $request['query'].'&' : '';*/ |
|
| 142 | + $query = '?'.$LogoutName; |
|
| 143 | 143 | |
| 144 | - return $request['path'].$query; |
|
| 144 | + return $request['path'].$query; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -150,348 +150,348 @@ discard block |
||
| 150 | 150 | * В противном случае вся работа происходит внутри самого блока |
| 151 | 151 | */ |
| 152 | 152 | public function AuthBlock($params){
|
| 153 | - $POST = array('backUrl' => $_SERVER['REQUEST_URI']);
|
|
| 154 | - |
|
| 155 | - $error = $errorCode = ''; |
|
| 156 | - |
|
| 157 | - $pwdField = APIHelpers::getkey($params, 'pwdField', 'password'); |
|
| 158 | - $emailField = APIHelpers::getkey($params, 'emailField', 'email'); |
|
| 159 | - $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
|
| 160 | - |
|
| 161 | - $type = 'web'; |
|
| 162 | - if($this->UserID(compact('type'))){
|
|
| 163 | - $tpl = APIHelpers::getkey($params, 'tplProfile', ''); |
|
| 164 | - if(empty($tpl)){
|
|
| 165 | - $tpl = $this->getTemplate('tplProfile');
|
|
| 166 | - } |
|
| 167 | - $dataTPL = $this->userObj->toArray(); |
|
| 168 | - $dataTPL['url.logout'] = $this->logoutUrl($params); |
|
| 169 | - $homeID = APIHelpers::getkey($params, 'homeID'); |
|
| 170 | - if(!empty($homeID)){
|
|
| 171 | - $dataTPL['url.profile'] = $this->makeUrl($homeID); |
|
| 172 | - } |
|
| 173 | - }else{
|
|
| 174 | - $tpl = APIHelpers::getkey($params, 'tplForm', ''); |
|
| 175 | - if(empty($tpl)){
|
|
| 176 | - $tpl = $this->getTemplate('authForm');
|
|
| 177 | - } |
|
| 178 | - $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
|
| 179 | - $dataTPL = array( |
|
| 180 | - 'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''), |
|
| 181 | - 'emailValue' => APIHelpers::getkey($POST, 'email', ''), |
|
| 182 | - 'emailField' => $emailField, |
|
| 183 | - 'pwdField' => $pwdField, |
|
| 184 | - 'method' => strtolower(__METHOD__), |
|
| 185 | - 'error' => $error, |
|
| 186 | - 'errorCode' => $errorCode |
|
| 187 | - ); |
|
| 188 | - $authId = APIHelpers::getkey($params, 'authId'); |
|
| 189 | - if(!empty($authId)){
|
|
| 190 | - $dataTPL['authPage'] = $this->makeUrl($authId); |
|
| 191 | - $dataTPL['method'] = strtolower(__CLASS__ . '::'. 'authpage'); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - return DLTemplate::getInstance($this->modx)->parseChunk($tpl, $dataTPL); |
|
| 153 | + $POST = array('backUrl' => $_SERVER['REQUEST_URI']);
|
|
| 154 | + |
|
| 155 | + $error = $errorCode = ''; |
|
| 156 | + |
|
| 157 | + $pwdField = APIHelpers::getkey($params, 'pwdField', 'password'); |
|
| 158 | + $emailField = APIHelpers::getkey($params, 'emailField', 'email'); |
|
| 159 | + $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
|
| 160 | + |
|
| 161 | + $type = 'web'; |
|
| 162 | + if($this->UserID(compact('type'))){
|
|
| 163 | + $tpl = APIHelpers::getkey($params, 'tplProfile', ''); |
|
| 164 | + if(empty($tpl)){
|
|
| 165 | + $tpl = $this->getTemplate('tplProfile');
|
|
| 166 | + } |
|
| 167 | + $dataTPL = $this->userObj->toArray(); |
|
| 168 | + $dataTPL['url.logout'] = $this->logoutUrl($params); |
|
| 169 | + $homeID = APIHelpers::getkey($params, 'homeID'); |
|
| 170 | + if(!empty($homeID)){
|
|
| 171 | + $dataTPL['url.profile'] = $this->makeUrl($homeID); |
|
| 172 | + } |
|
| 173 | + }else{
|
|
| 174 | + $tpl = APIHelpers::getkey($params, 'tplForm', ''); |
|
| 175 | + if(empty($tpl)){
|
|
| 176 | + $tpl = $this->getTemplate('authForm');
|
|
| 177 | + } |
|
| 178 | + $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
|
| 179 | + $dataTPL = array( |
|
| 180 | + 'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''), |
|
| 181 | + 'emailValue' => APIHelpers::getkey($POST, 'email', ''), |
|
| 182 | + 'emailField' => $emailField, |
|
| 183 | + 'pwdField' => $pwdField, |
|
| 184 | + 'method' => strtolower(__METHOD__), |
|
| 185 | + 'error' => $error, |
|
| 186 | + 'errorCode' => $errorCode |
|
| 187 | + ); |
|
| 188 | + $authId = APIHelpers::getkey($params, 'authId'); |
|
| 189 | + if(!empty($authId)){
|
|
| 190 | + $dataTPL['authPage'] = $this->makeUrl($authId); |
|
| 191 | + $dataTPL['method'] = strtolower(__CLASS__ . '::'. 'authpage'); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + return DLTemplate::getInstance($this->modx)->parseChunk($tpl, $dataTPL); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - /** |
|
| 198 | - * Авторизация на сайте со страницы авторизации |
|
| 199 | - * [!Auth? &login=`password` &pwdField=`password` &homeID=`72`!] |
|
| 200 | - */ |
|
| 201 | - public function AuthPage($params){
|
|
| 202 | - $homeID = APIHelpers::getkey($params, 'homeID'); |
|
| 203 | - $this->isAuthGoHome(array('id' => $homeID));
|
|
| 204 | - |
|
| 205 | - $error = $errorCode = ''; |
|
| 206 | - $POST = array('backUrl' => '');
|
|
| 207 | - |
|
| 208 | - $pwdField = APIHelpers::getkey($params, 'pwdField', 'password'); |
|
| 209 | - $emailField = APIHelpers::getkey($params, 'emailField', 'email'); |
|
| 210 | - $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
|
| 211 | - |
|
| 212 | - $tpl = APIHelpers::getkey($params, 'tpl', ''); |
|
| 213 | - if(empty($tpl)){
|
|
| 214 | - $tpl = $this->getTemplate('authForm');
|
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $request = parse_url($_SERVER['REQUEST_URI']); |
|
| 218 | - if(!empty($_SERVER['HTTP_REFERER'])){
|
|
| 219 | - /** |
|
| 220 | - * Thank you for super protection against hacking in protect.inc.php:-) |
|
| 221 | - */ |
|
| 222 | - $refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES); |
|
| 223 | - }else{
|
|
| 224 | - $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/');
|
|
| 225 | - if(empty( $request['host']) || $request['host']==$selfHost){
|
|
| 226 | - $query = !empty($request['query']) ? '?'.$request['query'] : ''; |
|
| 227 | - $refer = !empty($request['path']) ? $request['path'].$query : ''; |
|
| 228 | - }else{
|
|
| 229 | - $refer = ''; |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - if($_SERVER['REQUEST_METHOD'] == 'POST'){
|
|
| 234 | - $backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']); |
|
| 235 | - if(!is_scalar($backUrl)){
|
|
| 236 | - $backUrl = $refer; |
|
| 237 | - }else{
|
|
| 238 | - $backUrl = urldecode($backUrl); |
|
| 239 | - } |
|
| 240 | - }else{
|
|
| 241 | - $backUrl = $refer; |
|
| 242 | - } |
|
| 243 | - $backUrl = parse_url($backUrl); |
|
| 244 | - if(!empty($backUrl['path']) && $request['path'] != $backUrl['path']){
|
|
| 245 | - $POST['backUrl'] = $backUrl['path']; |
|
| 246 | - }else{
|
|
| 247 | - $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/');
|
|
| 248 | - if(empty($backUrl['host']) || $backUrl['host']==$selfHost){
|
|
| 249 | - $query = !empty($uri['query']) ? '?'.$backUrl['query'] : ''; |
|
| 250 | - $POST['backUrl'] = !empty($backUrl['path']) ? $backUrl['path'].$query : ''; |
|
| 251 | - }else{
|
|
| 252 | - $POST['backUrl'] = ''; |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - if(!empty($POST['backUrl'])){
|
|
| 256 | - $idURL = $this->moveTo(array( |
|
| 257 | - 'url' => '/'.ltrim($POST['backUrl'], '/'), |
|
| 258 | - 'validate' => true |
|
| 259 | - )); |
|
| 260 | - }else{
|
|
| 261 | - $idURL = 0; |
|
| 262 | - } |
|
| 263 | - if(empty($idURL)){
|
|
| 264 | - if(empty($homeID)){
|
|
| 265 | - $homeID = $this->config['site_start']; |
|
| 266 | - } |
|
| 267 | - $POST['backUrl'] = $this->makeUrl($homeID); |
|
| 268 | - } |
|
| 269 | - $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
|
| 270 | - return DLTemplate::getInstance($this->modx)->parseChunk($tpl, array( |
|
| 271 | - 'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''), |
|
| 272 | - 'emailValue' => APIHelpers::getkey($POST, 'email', ''), |
|
| 273 | - 'emailField' => $emailField, |
|
| 274 | - 'pwdField' => $pwdField, |
|
| 275 | - 'method' => strtolower(__METHOD__), |
|
| 276 | - 'error' => $error, |
|
| 277 | - 'errorCode' => $errorCode |
|
| 278 | - )); |
|
| 279 | - } |
|
| 280 | - protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()){
|
|
| 281 | - $POST = array( |
|
| 282 | - 'backUrl' => urlencode($backUrl) |
|
| 283 | - ); |
|
| 284 | - $userObj = &$this->userObj; |
|
| 285 | - if($_SERVER['REQUEST_METHOD']=='POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)){
|
|
| 286 | - $POST = array_merge($POST, array( |
|
| 287 | - 'password' => APIHelpers::getkey($_POST, $pwdField, ''), |
|
| 288 | - 'email' => APIHelpers::getkey($_POST, $emailField, ''), |
|
| 289 | - 'remember' => (bool)((int)APIHelpers::getkey($_POST, $rememberField, 0)) |
|
| 290 | - )); |
|
| 291 | - if(!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)){
|
|
| 292 | - $userObj->edit($POST['email']); |
|
| 293 | - |
|
| 294 | - $this->modx->invokeEvent("OnBeforeWebLogin", array(
|
|
| 295 | - "username" => $POST['email'], |
|
| 296 | - "userpassword" => $POST['password'], |
|
| 297 | - "rememberme" => $POST['remember'], |
|
| 298 | - 'userObj' => $userObj |
|
| 299 | - )); |
|
| 300 | - if($userObj->getID() && !$userObj->checkBlock($userObj->getID())){
|
|
| 301 | - $pluginFlag = $this->modx->invokeEvent("OnWebAuthentication", array(
|
|
| 302 | - "userid" => $userObj->getID(), |
|
| 303 | - "username" => $userObj->get('username'),
|
|
| 304 | - "userpassword" => $POST['password'], |
|
| 305 | - "savedpassword" => $userObj->get('password'),
|
|
| 306 | - "rememberme" => $POST['remember'], |
|
| 307 | - )); |
|
| 308 | - if( |
|
| 309 | - ($pluginFlag === true || $userObj->testAuth($userObj->getID(), $POST['password'], 0)) |
|
| 310 | - && |
|
| 311 | - $userObj->authUser($userObj->getID(), $POST['remember']) |
|
| 312 | - ){
|
|
| 313 | - $userObj->set('logincount', (int)$userObj->get('logincount') + 1);
|
|
| 314 | - $userObj->set('lastlogin', time());
|
|
| 315 | - $userObj->set('failedlogincount', 0);
|
|
| 316 | - $userObj->save(false, false); |
|
| 317 | - |
|
| 318 | - $this->modx->invokeEvent("OnWebLogin", array(
|
|
| 319 | - "userid" => $userObj->getID(), |
|
| 320 | - "username" => $userObj->get('username'),
|
|
| 321 | - "userpassword" => $POST['password'], |
|
| 322 | - "rememberme" => $POST['remember'], |
|
| 323 | - )); |
|
| 324 | - $this->moveTo(array('url' => urldecode($POST['backUrl'])));
|
|
| 325 | - }else{
|
|
| 326 | - $userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1);
|
|
| 327 | - $userObj->save(false, false); |
|
| 328 | - |
|
| 329 | - $error = 'error.incorrect_password'; |
|
| 330 | - } |
|
| 331 | - }else{
|
|
| 332 | - $error = 'error.no_user'; |
|
| 333 | - } |
|
| 334 | - }else{
|
|
| 335 | - $error = 'error.incorrect_mail'; |
|
| 336 | - $POST['email'] = ''; |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - if(!empty($error)){
|
|
| 340 | - $errorCode = $error; |
|
| 341 | - $error = APIHelpers::getkey($params, $error, ''); |
|
| 342 | - $error = static::getLangMsg($error, $error); |
|
| 343 | - } |
|
| 344 | - return $POST; |
|
| 345 | - } |
|
| 346 | - /** |
|
| 347 | - * Информация о пользователе |
|
| 348 | - * [!DLUsers? &action=`UserInfo` &field=`fullname` &id=`2`!] |
|
| 349 | - */ |
|
| 350 | - public function UserInfo($params){
|
|
| 351 | - $out = ''; |
|
| 352 | - $type = 'web'; |
|
| 353 | - $userID = APIHelpers::getkey($params, 'id', 0); |
|
| 354 | - if(empty($userID)){
|
|
| 355 | - $userID = $this->UserID(compact('type'));
|
|
| 356 | - } |
|
| 357 | - $field = APIHelpers::getkey($params, 'field', 'username'); |
|
| 358 | - if($userID > 0){
|
|
| 359 | - $this->userObj->edit($userID); |
|
| 360 | - switch(true){
|
|
| 361 | - case ($field == $this->userObj->fieldPKName()): |
|
| 362 | - $out = $this->userObj->getID(); |
|
| 363 | - break; |
|
| 364 | - case ($this->userObj->issetField($field)): |
|
| 365 | - $out = $this->userObj->get($field); |
|
| 366 | - break; |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - return $out; |
|
| 370 | - } |
|
| 371 | - /** |
|
| 372 | - * ID пользователя |
|
| 373 | - */ |
|
| 374 | - public function UserID(){
|
|
| 375 | - $type = 'web'; |
|
| 376 | - return $this->modx->getLoginUserID($type); |
|
| 377 | - } |
|
| 378 | - /** |
|
| 379 | - * Если не авторизован - то отправить на страницу |
|
| 380 | - */ |
|
| 381 | - public function isGuestGoHome($params){
|
|
| 382 | - $type = 'web'; |
|
| 383 | - if(!$this->UserID(compact('type'))){
|
|
| 384 | - /** |
|
| 385 | - * @see : http://modx.im/blog/triks/105.html |
|
| 386 | - */ |
|
| 387 | - $this->modx->invokeEvent('OnPageUnauthorized');
|
|
| 388 | - $id = APIHelpers::getkey($params, 'id', $this->config['unauthorized_page']); |
|
| 389 | - $this->moveTo(compact('id'));
|
|
| 390 | - } |
|
| 391 | - return; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * Если авторизован - то открыть личный кабинет |
|
| 396 | - */ |
|
| 397 | - public function isAuthGoHome($params){
|
|
| 398 | - $type = 'web'; |
|
| 399 | - $userID = $this->UserID(compact('type'));
|
|
| 400 | - if($userID>0){
|
|
| 401 | - $id = APIHelpers::getkey($params, 'homeID'); |
|
| 402 | - if(empty($id)){
|
|
| 403 | - $id = $this->modx->getConfig('login_home', $this->config['site_start']);
|
|
| 404 | - } |
|
| 405 | - $this->moveTo(compact('id'));
|
|
| 406 | - } |
|
| 407 | - return; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Редирект |
|
| 412 | - */ |
|
| 413 | - public function moveTo($params){
|
|
| 414 | - $id = (int)APIHelpers::getkey($params, 'id', 0); |
|
| 415 | - $uri = APIHelpers::getkey($params, 'url', ''); |
|
| 416 | - if((empty($uri) && !empty($id)) || !is_string($uri)){
|
|
| 417 | - $uri = $this->makeUrl($id); |
|
| 418 | - } |
|
| 419 | - $code = (int)APIHelpers::getkey($params, 'code', 0); |
|
| 420 | - $addUrl = APIHelpers::getkey($params, 'addUrl', ''); |
|
| 421 | - if(is_scalar($addUrl) && $addUrl!=''){
|
|
| 422 | - $uri .= "?".$addUrl; |
|
| 423 | - } |
|
| 424 | - if(APIHelpers::getkey($params, 'validate', false)){
|
|
| 425 | - if(isset($this->modx->snippetCache['getPageID'])){
|
|
| 426 | - $out = $this->modx->runSnippet('getPageID', compact('uri'));
|
|
| 427 | - if(empty($out)){
|
|
| 428 | - $uri = ''; |
|
| 429 | - } |
|
| 430 | - }else{
|
|
| 431 | - $uri = APIhelpers::sanitarTag($uri); |
|
| 432 | - } |
|
| 433 | - }else{
|
|
| 434 | - //$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect'); |
|
| 435 | - header("Location: ".$uri, true, ($code>0 ? $code : 307));
|
|
| 436 | - } |
|
| 437 | - return $uri; |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * Создание ссылки на страницу |
|
| 442 | - * |
|
| 443 | - * @param int $id ID документа |
|
| 444 | - * @return string |
|
| 445 | - */ |
|
| 446 | - protected function makeUrl($id = null){
|
|
| 447 | - $id = (int)$id; |
|
| 448 | - if($id <= 0){
|
|
| 449 | - $id = $this->modx->documentObject['id']; |
|
| 450 | - } |
|
| 451 | - if($this->url->containsKey($id)){
|
|
| 452 | - $url = $this->url->get($id); |
|
| 453 | - }else{
|
|
| 454 | - $url = $this->modx->makeUrl($id); |
|
| 455 | - $this->url->set($id, $url); |
|
| 456 | - } |
|
| 457 | - return $url; |
|
| 458 | - } |
|
| 459 | - protected function getTemplate($name){
|
|
| 460 | - $out = ''; |
|
| 461 | - $file = dirname(dirname(__FILE__)).'/tpl/'.$name.'.html'; |
|
| 462 | - if( FS::getInstance()->checkFile($file)){
|
|
| 463 | - $out = '@CODE: '.file_get_contents($file); |
|
| 464 | - } |
|
| 465 | - return $out; |
|
| 466 | - } |
|
| 467 | - protected static function loadLang($lang){
|
|
| 468 | - $file = dirname(dirname(__FILE__)).'/lang/'.$lang.'.php'; |
|
| 469 | - if( ! FS::getInstance()->checkFile($file)){
|
|
| 470 | - $file = false; |
|
| 471 | - } |
|
| 472 | - if(!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)){
|
|
| 473 | - static::$langDic[$lang] = include_once($file); |
|
| 474 | - if(is_array(static::$langDic[$lang])){
|
|
| 475 | - static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang); |
|
| 476 | - }else{
|
|
| 477 | - static::$langDic[$lang] = array(); |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - return !(empty($lang) || empty(static::$langDic[$lang])); |
|
| 481 | - } |
|
| 482 | - protected static function getLangMsg($key, $default){
|
|
| 483 | - $out = $default; |
|
| 484 | - $lng = static::$lang; |
|
| 485 | - $dic = static::$langDic; |
|
| 486 | - if(isset($dic[$lng], $dic[$lng][$lng.'.'.$key])){
|
|
| 487 | - $out = $dic[$lng][$lng.'.'.$key]; |
|
| 488 | - } |
|
| 489 | - if(class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])){
|
|
| 490 | - $msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.'.$key));
|
|
| 491 | - if(!empty($msg)){
|
|
| 492 | - $out = $msg; |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - return $out; |
|
| 496 | - } |
|
| 197 | + /** |
|
| 198 | + * Авторизация на сайте со страницы авторизации |
|
| 199 | + * [!Auth? &login=`password` &pwdField=`password` &homeID=`72`!] |
|
| 200 | + */ |
|
| 201 | + public function AuthPage($params){
|
|
| 202 | + $homeID = APIHelpers::getkey($params, 'homeID'); |
|
| 203 | + $this->isAuthGoHome(array('id' => $homeID));
|
|
| 204 | + |
|
| 205 | + $error = $errorCode = ''; |
|
| 206 | + $POST = array('backUrl' => '');
|
|
| 207 | + |
|
| 208 | + $pwdField = APIHelpers::getkey($params, 'pwdField', 'password'); |
|
| 209 | + $emailField = APIHelpers::getkey($params, 'emailField', 'email'); |
|
| 210 | + $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
|
| 211 | + |
|
| 212 | + $tpl = APIHelpers::getkey($params, 'tpl', ''); |
|
| 213 | + if(empty($tpl)){
|
|
| 214 | + $tpl = $this->getTemplate('authForm');
|
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $request = parse_url($_SERVER['REQUEST_URI']); |
|
| 218 | + if(!empty($_SERVER['HTTP_REFERER'])){
|
|
| 219 | + /** |
|
| 220 | + * Thank you for super protection against hacking in protect.inc.php:-) |
|
| 221 | + */ |
|
| 222 | + $refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES); |
|
| 223 | + }else{
|
|
| 224 | + $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/');
|
|
| 225 | + if(empty( $request['host']) || $request['host']==$selfHost){
|
|
| 226 | + $query = !empty($request['query']) ? '?'.$request['query'] : ''; |
|
| 227 | + $refer = !empty($request['path']) ? $request['path'].$query : ''; |
|
| 228 | + }else{
|
|
| 229 | + $refer = ''; |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + if($_SERVER['REQUEST_METHOD'] == 'POST'){
|
|
| 234 | + $backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']); |
|
| 235 | + if(!is_scalar($backUrl)){
|
|
| 236 | + $backUrl = $refer; |
|
| 237 | + }else{
|
|
| 238 | + $backUrl = urldecode($backUrl); |
|
| 239 | + } |
|
| 240 | + }else{
|
|
| 241 | + $backUrl = $refer; |
|
| 242 | + } |
|
| 243 | + $backUrl = parse_url($backUrl); |
|
| 244 | + if(!empty($backUrl['path']) && $request['path'] != $backUrl['path']){
|
|
| 245 | + $POST['backUrl'] = $backUrl['path']; |
|
| 246 | + }else{
|
|
| 247 | + $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/');
|
|
| 248 | + if(empty($backUrl['host']) || $backUrl['host']==$selfHost){
|
|
| 249 | + $query = !empty($uri['query']) ? '?'.$backUrl['query'] : ''; |
|
| 250 | + $POST['backUrl'] = !empty($backUrl['path']) ? $backUrl['path'].$query : ''; |
|
| 251 | + }else{
|
|
| 252 | + $POST['backUrl'] = ''; |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + if(!empty($POST['backUrl'])){
|
|
| 256 | + $idURL = $this->moveTo(array( |
|
| 257 | + 'url' => '/'.ltrim($POST['backUrl'], '/'), |
|
| 258 | + 'validate' => true |
|
| 259 | + )); |
|
| 260 | + }else{
|
|
| 261 | + $idURL = 0; |
|
| 262 | + } |
|
| 263 | + if(empty($idURL)){
|
|
| 264 | + if(empty($homeID)){
|
|
| 265 | + $homeID = $this->config['site_start']; |
|
| 266 | + } |
|
| 267 | + $POST['backUrl'] = $this->makeUrl($homeID); |
|
| 268 | + } |
|
| 269 | + $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
|
| 270 | + return DLTemplate::getInstance($this->modx)->parseChunk($tpl, array( |
|
| 271 | + 'backUrl' => APIHelpers::getkey($POST, 'backUrl', ''), |
|
| 272 | + 'emailValue' => APIHelpers::getkey($POST, 'email', ''), |
|
| 273 | + 'emailField' => $emailField, |
|
| 274 | + 'pwdField' => $pwdField, |
|
| 275 | + 'method' => strtolower(__METHOD__), |
|
| 276 | + 'error' => $error, |
|
| 277 | + 'errorCode' => $errorCode |
|
| 278 | + )); |
|
| 279 | + } |
|
| 280 | + protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()){
|
|
| 281 | + $POST = array( |
|
| 282 | + 'backUrl' => urlencode($backUrl) |
|
| 283 | + ); |
|
| 284 | + $userObj = &$this->userObj; |
|
| 285 | + if($_SERVER['REQUEST_METHOD']=='POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)){
|
|
| 286 | + $POST = array_merge($POST, array( |
|
| 287 | + 'password' => APIHelpers::getkey($_POST, $pwdField, ''), |
|
| 288 | + 'email' => APIHelpers::getkey($_POST, $emailField, ''), |
|
| 289 | + 'remember' => (bool)((int)APIHelpers::getkey($_POST, $rememberField, 0)) |
|
| 290 | + )); |
|
| 291 | + if(!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)){
|
|
| 292 | + $userObj->edit($POST['email']); |
|
| 293 | + |
|
| 294 | + $this->modx->invokeEvent("OnBeforeWebLogin", array(
|
|
| 295 | + "username" => $POST['email'], |
|
| 296 | + "userpassword" => $POST['password'], |
|
| 297 | + "rememberme" => $POST['remember'], |
|
| 298 | + 'userObj' => $userObj |
|
| 299 | + )); |
|
| 300 | + if($userObj->getID() && !$userObj->checkBlock($userObj->getID())){
|
|
| 301 | + $pluginFlag = $this->modx->invokeEvent("OnWebAuthentication", array(
|
|
| 302 | + "userid" => $userObj->getID(), |
|
| 303 | + "username" => $userObj->get('username'),
|
|
| 304 | + "userpassword" => $POST['password'], |
|
| 305 | + "savedpassword" => $userObj->get('password'),
|
|
| 306 | + "rememberme" => $POST['remember'], |
|
| 307 | + )); |
|
| 308 | + if( |
|
| 309 | + ($pluginFlag === true || $userObj->testAuth($userObj->getID(), $POST['password'], 0)) |
|
| 310 | + && |
|
| 311 | + $userObj->authUser($userObj->getID(), $POST['remember']) |
|
| 312 | + ){
|
|
| 313 | + $userObj->set('logincount', (int)$userObj->get('logincount') + 1);
|
|
| 314 | + $userObj->set('lastlogin', time());
|
|
| 315 | + $userObj->set('failedlogincount', 0);
|
|
| 316 | + $userObj->save(false, false); |
|
| 317 | + |
|
| 318 | + $this->modx->invokeEvent("OnWebLogin", array(
|
|
| 319 | + "userid" => $userObj->getID(), |
|
| 320 | + "username" => $userObj->get('username'),
|
|
| 321 | + "userpassword" => $POST['password'], |
|
| 322 | + "rememberme" => $POST['remember'], |
|
| 323 | + )); |
|
| 324 | + $this->moveTo(array('url' => urldecode($POST['backUrl'])));
|
|
| 325 | + }else{
|
|
| 326 | + $userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1);
|
|
| 327 | + $userObj->save(false, false); |
|
| 328 | + |
|
| 329 | + $error = 'error.incorrect_password'; |
|
| 330 | + } |
|
| 331 | + }else{
|
|
| 332 | + $error = 'error.no_user'; |
|
| 333 | + } |
|
| 334 | + }else{
|
|
| 335 | + $error = 'error.incorrect_mail'; |
|
| 336 | + $POST['email'] = ''; |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + if(!empty($error)){
|
|
| 340 | + $errorCode = $error; |
|
| 341 | + $error = APIHelpers::getkey($params, $error, ''); |
|
| 342 | + $error = static::getLangMsg($error, $error); |
|
| 343 | + } |
|
| 344 | + return $POST; |
|
| 345 | + } |
|
| 346 | + /** |
|
| 347 | + * Информация о пользователе |
|
| 348 | + * [!DLUsers? &action=`UserInfo` &field=`fullname` &id=`2`!] |
|
| 349 | + */ |
|
| 350 | + public function UserInfo($params){
|
|
| 351 | + $out = ''; |
|
| 352 | + $type = 'web'; |
|
| 353 | + $userID = APIHelpers::getkey($params, 'id', 0); |
|
| 354 | + if(empty($userID)){
|
|
| 355 | + $userID = $this->UserID(compact('type'));
|
|
| 356 | + } |
|
| 357 | + $field = APIHelpers::getkey($params, 'field', 'username'); |
|
| 358 | + if($userID > 0){
|
|
| 359 | + $this->userObj->edit($userID); |
|
| 360 | + switch(true){
|
|
| 361 | + case ($field == $this->userObj->fieldPKName()): |
|
| 362 | + $out = $this->userObj->getID(); |
|
| 363 | + break; |
|
| 364 | + case ($this->userObj->issetField($field)): |
|
| 365 | + $out = $this->userObj->get($field); |
|
| 366 | + break; |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + return $out; |
|
| 370 | + } |
|
| 371 | + /** |
|
| 372 | + * ID пользователя |
|
| 373 | + */ |
|
| 374 | + public function UserID(){
|
|
| 375 | + $type = 'web'; |
|
| 376 | + return $this->modx->getLoginUserID($type); |
|
| 377 | + } |
|
| 378 | + /** |
|
| 379 | + * Если не авторизован - то отправить на страницу |
|
| 380 | + */ |
|
| 381 | + public function isGuestGoHome($params){
|
|
| 382 | + $type = 'web'; |
|
| 383 | + if(!$this->UserID(compact('type'))){
|
|
| 384 | + /** |
|
| 385 | + * @see : http://modx.im/blog/triks/105.html |
|
| 386 | + */ |
|
| 387 | + $this->modx->invokeEvent('OnPageUnauthorized');
|
|
| 388 | + $id = APIHelpers::getkey($params, 'id', $this->config['unauthorized_page']); |
|
| 389 | + $this->moveTo(compact('id'));
|
|
| 390 | + } |
|
| 391 | + return; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * Если авторизован - то открыть личный кабинет |
|
| 396 | + */ |
|
| 397 | + public function isAuthGoHome($params){
|
|
| 398 | + $type = 'web'; |
|
| 399 | + $userID = $this->UserID(compact('type'));
|
|
| 400 | + if($userID>0){
|
|
| 401 | + $id = APIHelpers::getkey($params, 'homeID'); |
|
| 402 | + if(empty($id)){
|
|
| 403 | + $id = $this->modx->getConfig('login_home', $this->config['site_start']);
|
|
| 404 | + } |
|
| 405 | + $this->moveTo(compact('id'));
|
|
| 406 | + } |
|
| 407 | + return; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Редирект |
|
| 412 | + */ |
|
| 413 | + public function moveTo($params){
|
|
| 414 | + $id = (int)APIHelpers::getkey($params, 'id', 0); |
|
| 415 | + $uri = APIHelpers::getkey($params, 'url', ''); |
|
| 416 | + if((empty($uri) && !empty($id)) || !is_string($uri)){
|
|
| 417 | + $uri = $this->makeUrl($id); |
|
| 418 | + } |
|
| 419 | + $code = (int)APIHelpers::getkey($params, 'code', 0); |
|
| 420 | + $addUrl = APIHelpers::getkey($params, 'addUrl', ''); |
|
| 421 | + if(is_scalar($addUrl) && $addUrl!=''){
|
|
| 422 | + $uri .= "?".$addUrl; |
|
| 423 | + } |
|
| 424 | + if(APIHelpers::getkey($params, 'validate', false)){
|
|
| 425 | + if(isset($this->modx->snippetCache['getPageID'])){
|
|
| 426 | + $out = $this->modx->runSnippet('getPageID', compact('uri'));
|
|
| 427 | + if(empty($out)){
|
|
| 428 | + $uri = ''; |
|
| 429 | + } |
|
| 430 | + }else{
|
|
| 431 | + $uri = APIhelpers::sanitarTag($uri); |
|
| 432 | + } |
|
| 433 | + }else{
|
|
| 434 | + //$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect'); |
|
| 435 | + header("Location: ".$uri, true, ($code>0 ? $code : 307));
|
|
| 436 | + } |
|
| 437 | + return $uri; |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * Создание ссылки на страницу |
|
| 442 | + * |
|
| 443 | + * @param int $id ID документа |
|
| 444 | + * @return string |
|
| 445 | + */ |
|
| 446 | + protected function makeUrl($id = null){
|
|
| 447 | + $id = (int)$id; |
|
| 448 | + if($id <= 0){
|
|
| 449 | + $id = $this->modx->documentObject['id']; |
|
| 450 | + } |
|
| 451 | + if($this->url->containsKey($id)){
|
|
| 452 | + $url = $this->url->get($id); |
|
| 453 | + }else{
|
|
| 454 | + $url = $this->modx->makeUrl($id); |
|
| 455 | + $this->url->set($id, $url); |
|
| 456 | + } |
|
| 457 | + return $url; |
|
| 458 | + } |
|
| 459 | + protected function getTemplate($name){
|
|
| 460 | + $out = ''; |
|
| 461 | + $file = dirname(dirname(__FILE__)).'/tpl/'.$name.'.html'; |
|
| 462 | + if( FS::getInstance()->checkFile($file)){
|
|
| 463 | + $out = '@CODE: '.file_get_contents($file); |
|
| 464 | + } |
|
| 465 | + return $out; |
|
| 466 | + } |
|
| 467 | + protected static function loadLang($lang){
|
|
| 468 | + $file = dirname(dirname(__FILE__)).'/lang/'.$lang.'.php'; |
|
| 469 | + if( ! FS::getInstance()->checkFile($file)){
|
|
| 470 | + $file = false; |
|
| 471 | + } |
|
| 472 | + if(!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)){
|
|
| 473 | + static::$langDic[$lang] = include_once($file); |
|
| 474 | + if(is_array(static::$langDic[$lang])){
|
|
| 475 | + static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang); |
|
| 476 | + }else{
|
|
| 477 | + static::$langDic[$lang] = array(); |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + return !(empty($lang) || empty(static::$langDic[$lang])); |
|
| 481 | + } |
|
| 482 | + protected static function getLangMsg($key, $default){
|
|
| 483 | + $out = $default; |
|
| 484 | + $lng = static::$lang; |
|
| 485 | + $dic = static::$langDic; |
|
| 486 | + if(isset($dic[$lng], $dic[$lng][$lng.'.'.$key])){
|
|
| 487 | + $out = $dic[$lng][$lng.'.'.$key]; |
|
| 488 | + } |
|
| 489 | + if(class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])){
|
|
| 490 | + $msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.'.$key));
|
|
| 491 | + if(!empty($msg)){
|
|
| 492 | + $out = $msg; |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + return $out; |
|
| 496 | + } |
|
| 497 | 497 | } |
| 498 | 498 | \ No newline at end of file |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | use APIHelpers, DocumentParser, DLCollection, DLTemplate; |
| 10 | 10 | use Helpers\FS; |
| 11 | 11 | |
| 12 | -class Actions{
|
|
| 12 | +class Actions {
|
|
| 13 | 13 | protected $modx = null; |
| 14 | 14 | public $userObj = null; |
| 15 | 15 | /** |
@@ -84,21 +84,21 @@ discard block |
||
| 84 | 84 | /** |
| 85 | 85 | * Сброс авторизации и обновление страницы |
| 86 | 86 | */ |
| 87 | - public function logout($params){
|
|
| 87 | + public function logout($params) {
|
|
| 88 | 88 | $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
| 89 | - if(is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])){
|
|
| 89 | + if (is_scalar($LogoutName) && !empty($LogoutName) && isset($_GET[$LogoutName])) {
|
|
| 90 | 90 | $type = 'web'; |
| 91 | 91 | $userID = $this->UserID(compact('type'));
|
| 92 | - if($userID){
|
|
| 92 | + if ($userID) {
|
|
| 93 | 93 | $this->userObj->edit($userID); |
| 94 | - if($this->userObj->getID()){
|
|
| 94 | + if ($this->userObj->getID()) {
|
|
| 95 | 95 | $this->modx->invokeEvent("OnBeforeWebLogout", array(
|
| 96 | 96 | "userid" => $this->userObj->getID(), |
| 97 | 97 | "username" => $this->userObj->get('username')
|
| 98 | 98 | )); |
| 99 | 99 | } |
| 100 | 100 | $this->userObj->logOut(); |
| 101 | - if($this->userObj->getID()){
|
|
| 101 | + if ($this->userObj->getID()) {
|
|
| 102 | 102 | $this->modx->invokeEvent("OnWebLogout", array(
|
| 103 | 103 | "userid" => $this->userObj->getID(), |
| 104 | 104 | "username" => $this->userObj->get('username')
|
@@ -106,22 +106,22 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | $go = APIHelpers::getkey($params, 'url', ''); |
| 109 | - if(empty($go)){
|
|
| 109 | + if (empty($go)) {
|
|
| 110 | 110 | $go = str_replace( |
| 111 | - array("?".$LogoutName, "&".$LogoutName),
|
|
| 111 | + array("?" . $LogoutName, "&" . $LogoutName),
|
|
| 112 | 112 | array("", ""),
|
| 113 | 113 | $_SERVER['REQUEST_URI'] |
| 114 | 114 | ); |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | $start = $this->makeUrl($this->config['site_start']); |
| 118 | - if($start == $go){
|
|
| 118 | + if ($start == $go) {
|
|
| 119 | 119 | $go = $this->config['site_url']; |
| 120 | - }else{
|
|
| 121 | - $go = $this->config['site_url'].ltrim($go, '/'); |
|
| 120 | + } else {
|
|
| 121 | + $go = $this->config['site_url'] . ltrim($go, '/'); |
|
| 122 | 122 | } |
| 123 | 123 | $this->moveTo(array('url' => $go));
|
| 124 | - }else{
|
|
| 124 | + } else {
|
|
| 125 | 125 | //Если юзер не авторизован, то показываем ему 404 ошибку |
| 126 | 126 | $this->modx->sendErrorPage(); |
| 127 | 127 | } |
@@ -133,15 +133,15 @@ discard block |
||
| 133 | 133 | * Генерация ссылки под кнопку выход |
| 134 | 134 | * @return string |
| 135 | 135 | */ |
| 136 | - public function logoutUrl($params){
|
|
| 136 | + public function logoutUrl($params) {
|
|
| 137 | 137 | $LogoutName = APIHelpers::getkey($params, 'LogoutName', 'logout'); |
| 138 | 138 | $request = parse_url($_SERVER['REQUEST_URI']); |
| 139 | 139 | |
| 140 | 140 | //Во избежании XSS мы не сохраняем весь REQUEST_URI, а берем только path |
| 141 | 141 | /*$query = (!empty($request['query'])) ? $request['query'].'&' : '';*/ |
| 142 | - $query = '?'.$LogoutName; |
|
| 142 | + $query = '?' . $LogoutName; |
|
| 143 | 143 | |
| 144 | - return $request['path'].$query; |
|
| 144 | + return $request['path'] . $query; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * если указан параметр authId, то данные из формы перекидываются в метод AuthPage |
| 150 | 150 | * В противном случае вся работа происходит внутри самого блока |
| 151 | 151 | */ |
| 152 | - public function AuthBlock($params){
|
|
| 152 | + public function AuthBlock($params) {
|
|
| 153 | 153 | $POST = array('backUrl' => $_SERVER['REQUEST_URI']);
|
| 154 | 154 | |
| 155 | 155 | $error = $errorCode = ''; |
@@ -159,20 +159,20 @@ discard block |
||
| 159 | 159 | $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
| 160 | 160 | |
| 161 | 161 | $type = 'web'; |
| 162 | - if($this->UserID(compact('type'))){
|
|
| 162 | + if ($this->UserID(compact('type'))) {
|
|
| 163 | 163 | $tpl = APIHelpers::getkey($params, 'tplProfile', ''); |
| 164 | - if(empty($tpl)){
|
|
| 164 | + if (empty($tpl)) {
|
|
| 165 | 165 | $tpl = $this->getTemplate('tplProfile');
|
| 166 | 166 | } |
| 167 | 167 | $dataTPL = $this->userObj->toArray(); |
| 168 | 168 | $dataTPL['url.logout'] = $this->logoutUrl($params); |
| 169 | 169 | $homeID = APIHelpers::getkey($params, 'homeID'); |
| 170 | - if(!empty($homeID)){
|
|
| 170 | + if (!empty($homeID)) {
|
|
| 171 | 171 | $dataTPL['url.profile'] = $this->makeUrl($homeID); |
| 172 | 172 | } |
| 173 | - }else{
|
|
| 173 | + } else {
|
|
| 174 | 174 | $tpl = APIHelpers::getkey($params, 'tplForm', ''); |
| 175 | - if(empty($tpl)){
|
|
| 175 | + if (empty($tpl)) {
|
|
| 176 | 176 | $tpl = $this->getTemplate('authForm');
|
| 177 | 177 | } |
| 178 | 178 | $POST = $this->Auth($pwdField, $emailField, $rememberField, $POST['backUrl'], __METHOD__, $error, $errorCode, $params); |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | 'errorCode' => $errorCode |
| 187 | 187 | ); |
| 188 | 188 | $authId = APIHelpers::getkey($params, 'authId'); |
| 189 | - if(!empty($authId)){
|
|
| 189 | + if (!empty($authId)) {
|
|
| 190 | 190 | $dataTPL['authPage'] = $this->makeUrl($authId); |
| 191 | - $dataTPL['method'] = strtolower(__CLASS__ . '::'. 'authpage'); |
|
| 191 | + $dataTPL['method'] = strtolower(__CLASS__ . '::' . 'authpage'); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | return DLTemplate::getInstance($this->modx)->parseChunk($tpl, $dataTPL); |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * Авторизация на сайте со страницы авторизации |
| 199 | 199 | * [!Auth? &login=`password` &pwdField=`password` &homeID=`72`!] |
| 200 | 200 | */ |
| 201 | - public function AuthPage($params){
|
|
| 201 | + public function AuthPage($params) {
|
|
| 202 | 202 | $homeID = APIHelpers::getkey($params, 'homeID'); |
| 203 | 203 | $this->isAuthGoHome(array('id' => $homeID));
|
| 204 | 204 | |
@@ -210,58 +210,58 @@ discard block |
||
| 210 | 210 | $rememberField = APIHelpers::getkey($params, 'rememberField', 'remember'); |
| 211 | 211 | |
| 212 | 212 | $tpl = APIHelpers::getkey($params, 'tpl', ''); |
| 213 | - if(empty($tpl)){
|
|
| 213 | + if (empty($tpl)) {
|
|
| 214 | 214 | $tpl = $this->getTemplate('authForm');
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | $request = parse_url($_SERVER['REQUEST_URI']); |
| 218 | - if(!empty($_SERVER['HTTP_REFERER'])){
|
|
| 218 | + if (!empty($_SERVER['HTTP_REFERER'])) {
|
|
| 219 | 219 | /** |
| 220 | 220 | * Thank you for super protection against hacking in protect.inc.php:-) |
| 221 | 221 | */ |
| 222 | 222 | $refer = htmlspecialchars_decode($_SERVER['HTTP_REFERER'], ENT_QUOTES); |
| 223 | - }else{
|
|
| 223 | + } else {
|
|
| 224 | 224 | $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/');
|
| 225 | - if(empty( $request['host']) || $request['host']==$selfHost){
|
|
| 226 | - $query = !empty($request['query']) ? '?'.$request['query'] : ''; |
|
| 227 | - $refer = !empty($request['path']) ? $request['path'].$query : ''; |
|
| 228 | - }else{
|
|
| 225 | + if (empty($request['host']) || $request['host'] == $selfHost) {
|
|
| 226 | + $query = !empty($request['query']) ? '?' . $request['query'] : ''; |
|
| 227 | + $refer = !empty($request['path']) ? $request['path'] . $query : ''; |
|
| 228 | + } else {
|
|
| 229 | 229 | $refer = ''; |
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - if($_SERVER['REQUEST_METHOD'] == 'POST'){
|
|
| 233 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
| 234 | 234 | $backUrl = APIHelpers::getkey($_POST, 'backUrl', $POST['backUrl']); |
| 235 | - if(!is_scalar($backUrl)){
|
|
| 235 | + if (!is_scalar($backUrl)) {
|
|
| 236 | 236 | $backUrl = $refer; |
| 237 | - }else{
|
|
| 237 | + } else {
|
|
| 238 | 238 | $backUrl = urldecode($backUrl); |
| 239 | 239 | } |
| 240 | - }else{
|
|
| 240 | + } else {
|
|
| 241 | 241 | $backUrl = $refer; |
| 242 | 242 | } |
| 243 | 243 | $backUrl = parse_url($backUrl); |
| 244 | - if(!empty($backUrl['path']) && $request['path'] != $backUrl['path']){
|
|
| 244 | + if (!empty($backUrl['path']) && $request['path'] != $backUrl['path']) {
|
|
| 245 | 245 | $POST['backUrl'] = $backUrl['path']; |
| 246 | - }else{
|
|
| 246 | + } else {
|
|
| 247 | 247 | $selfHost = rtrim(str_replace("http://", "", $this->config['site_url']), '/');
|
| 248 | - if(empty($backUrl['host']) || $backUrl['host']==$selfHost){
|
|
| 249 | - $query = !empty($uri['query']) ? '?'.$backUrl['query'] : ''; |
|
| 250 | - $POST['backUrl'] = !empty($backUrl['path']) ? $backUrl['path'].$query : ''; |
|
| 251 | - }else{
|
|
| 248 | + if (empty($backUrl['host']) || $backUrl['host'] == $selfHost) {
|
|
| 249 | + $query = !empty($uri['query']) ? '?' . $backUrl['query'] : ''; |
|
| 250 | + $POST['backUrl'] = !empty($backUrl['path']) ? $backUrl['path'] . $query : ''; |
|
| 251 | + } else {
|
|
| 252 | 252 | $POST['backUrl'] = ''; |
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | - if(!empty($POST['backUrl'])){
|
|
| 255 | + if (!empty($POST['backUrl'])) {
|
|
| 256 | 256 | $idURL = $this->moveTo(array( |
| 257 | - 'url' => '/'.ltrim($POST['backUrl'], '/'), |
|
| 257 | + 'url' => '/' . ltrim($POST['backUrl'], '/'), |
|
| 258 | 258 | 'validate' => true |
| 259 | 259 | )); |
| 260 | - }else{
|
|
| 260 | + } else {
|
|
| 261 | 261 | $idURL = 0; |
| 262 | 262 | } |
| 263 | - if(empty($idURL)){
|
|
| 264 | - if(empty($homeID)){
|
|
| 263 | + if (empty($idURL)) {
|
|
| 264 | + if (empty($homeID)) {
|
|
| 265 | 265 | $homeID = $this->config['site_start']; |
| 266 | 266 | } |
| 267 | 267 | $POST['backUrl'] = $this->makeUrl($homeID); |
@@ -277,18 +277,18 @@ discard block |
||
| 277 | 277 | 'errorCode' => $errorCode |
| 278 | 278 | )); |
| 279 | 279 | } |
| 280 | - protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()){
|
|
| 280 | + protected function Auth($pwdField, $emailField, $rememberField, $backUrl, $method, &$error, &$errorCode, $params = array()) {
|
|
| 281 | 281 | $POST = array( |
| 282 | 282 | 'backUrl' => urlencode($backUrl) |
| 283 | 283 | ); |
| 284 | 284 | $userObj = &$this->userObj; |
| 285 | - if($_SERVER['REQUEST_METHOD']=='POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)){
|
|
| 285 | + if ($_SERVER['REQUEST_METHOD'] == 'POST' && APIHelpers::getkey($_POST, 'method', '') == strtolower($method)) {
|
|
| 286 | 286 | $POST = array_merge($POST, array( |
| 287 | 287 | 'password' => APIHelpers::getkey($_POST, $pwdField, ''), |
| 288 | 288 | 'email' => APIHelpers::getkey($_POST, $emailField, ''), |
| 289 | 289 | 'remember' => (bool)((int)APIHelpers::getkey($_POST, $rememberField, 0)) |
| 290 | 290 | )); |
| 291 | - if(!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)){
|
|
| 291 | + if (!empty($POST['email']) && is_scalar($POST['email']) && !$userObj->emailValidate($POST['email'], false)) {
|
|
| 292 | 292 | $userObj->edit($POST['email']); |
| 293 | 293 | |
| 294 | 294 | $this->modx->invokeEvent("OnBeforeWebLogin", array(
|
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | "rememberme" => $POST['remember'], |
| 298 | 298 | 'userObj' => $userObj |
| 299 | 299 | )); |
| 300 | - if($userObj->getID() && !$userObj->checkBlock($userObj->getID())){
|
|
| 300 | + if ($userObj->getID() && !$userObj->checkBlock($userObj->getID())) {
|
|
| 301 | 301 | $pluginFlag = $this->modx->invokeEvent("OnWebAuthentication", array(
|
| 302 | 302 | "userid" => $userObj->getID(), |
| 303 | 303 | "username" => $userObj->get('username'),
|
@@ -305,11 +305,11 @@ discard block |
||
| 305 | 305 | "savedpassword" => $userObj->get('password'),
|
| 306 | 306 | "rememberme" => $POST['remember'], |
| 307 | 307 | )); |
| 308 | - if( |
|
| 308 | + if ( |
|
| 309 | 309 | ($pluginFlag === true || $userObj->testAuth($userObj->getID(), $POST['password'], 0)) |
| 310 | 310 | && |
| 311 | 311 | $userObj->authUser($userObj->getID(), $POST['remember']) |
| 312 | - ){
|
|
| 312 | + ) {
|
|
| 313 | 313 | $userObj->set('logincount', (int)$userObj->get('logincount') + 1);
|
| 314 | 314 | $userObj->set('lastlogin', time());
|
| 315 | 315 | $userObj->set('failedlogincount', 0);
|
@@ -322,21 +322,21 @@ discard block |
||
| 322 | 322 | "rememberme" => $POST['remember'], |
| 323 | 323 | )); |
| 324 | 324 | $this->moveTo(array('url' => urldecode($POST['backUrl'])));
|
| 325 | - }else{
|
|
| 325 | + } else {
|
|
| 326 | 326 | $userObj->set('failedlogincount', (int)$userObj->get('failedlogincount') + 1);
|
| 327 | 327 | $userObj->save(false, false); |
| 328 | 328 | |
| 329 | 329 | $error = 'error.incorrect_password'; |
| 330 | 330 | } |
| 331 | - }else{
|
|
| 331 | + } else {
|
|
| 332 | 332 | $error = 'error.no_user'; |
| 333 | 333 | } |
| 334 | - }else{
|
|
| 334 | + } else {
|
|
| 335 | 335 | $error = 'error.incorrect_mail'; |
| 336 | 336 | $POST['email'] = ''; |
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | - if(!empty($error)){
|
|
| 339 | + if (!empty($error)) {
|
|
| 340 | 340 | $errorCode = $error; |
| 341 | 341 | $error = APIHelpers::getkey($params, $error, ''); |
| 342 | 342 | $error = static::getLangMsg($error, $error); |
@@ -347,17 +347,17 @@ discard block |
||
| 347 | 347 | * Информация о пользователе |
| 348 | 348 | * [!DLUsers? &action=`UserInfo` &field=`fullname` &id=`2`!] |
| 349 | 349 | */ |
| 350 | - public function UserInfo($params){
|
|
| 350 | + public function UserInfo($params) {
|
|
| 351 | 351 | $out = ''; |
| 352 | 352 | $type = 'web'; |
| 353 | 353 | $userID = APIHelpers::getkey($params, 'id', 0); |
| 354 | - if(empty($userID)){
|
|
| 354 | + if (empty($userID)) {
|
|
| 355 | 355 | $userID = $this->UserID(compact('type'));
|
| 356 | 356 | } |
| 357 | 357 | $field = APIHelpers::getkey($params, 'field', 'username'); |
| 358 | - if($userID > 0){
|
|
| 358 | + if ($userID > 0) {
|
|
| 359 | 359 | $this->userObj->edit($userID); |
| 360 | - switch(true){
|
|
| 360 | + switch (true) {
|
|
| 361 | 361 | case ($field == $this->userObj->fieldPKName()): |
| 362 | 362 | $out = $this->userObj->getID(); |
| 363 | 363 | break; |
@@ -371,16 +371,16 @@ discard block |
||
| 371 | 371 | /** |
| 372 | 372 | * ID пользователя |
| 373 | 373 | */ |
| 374 | - public function UserID(){
|
|
| 374 | + public function UserID() {
|
|
| 375 | 375 | $type = 'web'; |
| 376 | 376 | return $this->modx->getLoginUserID($type); |
| 377 | 377 | } |
| 378 | 378 | /** |
| 379 | 379 | * Если не авторизован - то отправить на страницу |
| 380 | 380 | */ |
| 381 | - public function isGuestGoHome($params){
|
|
| 381 | + public function isGuestGoHome($params) {
|
|
| 382 | 382 | $type = 'web'; |
| 383 | - if(!$this->UserID(compact('type'))){
|
|
| 383 | + if (!$this->UserID(compact('type'))) {
|
|
| 384 | 384 | /** |
| 385 | 385 | * @see : http://modx.im/blog/triks/105.html |
| 386 | 386 | */ |
@@ -394,12 +394,12 @@ discard block |
||
| 394 | 394 | /** |
| 395 | 395 | * Если авторизован - то открыть личный кабинет |
| 396 | 396 | */ |
| 397 | - public function isAuthGoHome($params){
|
|
| 397 | + public function isAuthGoHome($params) {
|
|
| 398 | 398 | $type = 'web'; |
| 399 | 399 | $userID = $this->UserID(compact('type'));
|
| 400 | - if($userID>0){
|
|
| 400 | + if ($userID > 0) {
|
|
| 401 | 401 | $id = APIHelpers::getkey($params, 'homeID'); |
| 402 | - if(empty($id)){
|
|
| 402 | + if (empty($id)) {
|
|
| 403 | 403 | $id = $this->modx->getConfig('login_home', $this->config['site_start']);
|
| 404 | 404 | } |
| 405 | 405 | $this->moveTo(compact('id'));
|
@@ -410,29 +410,29 @@ discard block |
||
| 410 | 410 | /** |
| 411 | 411 | * Редирект |
| 412 | 412 | */ |
| 413 | - public function moveTo($params){
|
|
| 413 | + public function moveTo($params) {
|
|
| 414 | 414 | $id = (int)APIHelpers::getkey($params, 'id', 0); |
| 415 | 415 | $uri = APIHelpers::getkey($params, 'url', ''); |
| 416 | - if((empty($uri) && !empty($id)) || !is_string($uri)){
|
|
| 416 | + if ((empty($uri) && !empty($id)) || !is_string($uri)) {
|
|
| 417 | 417 | $uri = $this->makeUrl($id); |
| 418 | 418 | } |
| 419 | 419 | $code = (int)APIHelpers::getkey($params, 'code', 0); |
| 420 | 420 | $addUrl = APIHelpers::getkey($params, 'addUrl', ''); |
| 421 | - if(is_scalar($addUrl) && $addUrl!=''){
|
|
| 422 | - $uri .= "?".$addUrl; |
|
| 421 | + if (is_scalar($addUrl) && $addUrl != '') {
|
|
| 422 | + $uri .= "?" . $addUrl; |
|
| 423 | 423 | } |
| 424 | - if(APIHelpers::getkey($params, 'validate', false)){
|
|
| 425 | - if(isset($this->modx->snippetCache['getPageID'])){
|
|
| 424 | + if (APIHelpers::getkey($params, 'validate', false)) {
|
|
| 425 | + if (isset($this->modx->snippetCache['getPageID'])) {
|
|
| 426 | 426 | $out = $this->modx->runSnippet('getPageID', compact('uri'));
|
| 427 | - if(empty($out)){
|
|
| 427 | + if (empty($out)) {
|
|
| 428 | 428 | $uri = ''; |
| 429 | 429 | } |
| 430 | - }else{
|
|
| 430 | + } else {
|
|
| 431 | 431 | $uri = APIhelpers::sanitarTag($uri); |
| 432 | 432 | } |
| 433 | - }else{
|
|
| 433 | + } else {
|
|
| 434 | 434 | //$modx->sendRedirect($url, 0, 'REDIRECT_HEADER', 'HTTP/1.1 307 Temporary Redirect'); |
| 435 | - header("Location: ".$uri, true, ($code>0 ? $code : 307));
|
|
| 435 | + header("Location: " . $uri, true, ($code > 0 ? $code : 307));
|
|
| 436 | 436 | } |
| 437 | 437 | return $uri; |
| 438 | 438 | } |
@@ -443,52 +443,52 @@ discard block |
||
| 443 | 443 | * @param int $id ID документа |
| 444 | 444 | * @return string |
| 445 | 445 | */ |
| 446 | - protected function makeUrl($id = null){
|
|
| 446 | + protected function makeUrl($id = null) {
|
|
| 447 | 447 | $id = (int)$id; |
| 448 | - if($id <= 0){
|
|
| 448 | + if ($id <= 0) {
|
|
| 449 | 449 | $id = $this->modx->documentObject['id']; |
| 450 | 450 | } |
| 451 | - if($this->url->containsKey($id)){
|
|
| 451 | + if ($this->url->containsKey($id)) {
|
|
| 452 | 452 | $url = $this->url->get($id); |
| 453 | - }else{
|
|
| 453 | + } else {
|
|
| 454 | 454 | $url = $this->modx->makeUrl($id); |
| 455 | 455 | $this->url->set($id, $url); |
| 456 | 456 | } |
| 457 | 457 | return $url; |
| 458 | 458 | } |
| 459 | - protected function getTemplate($name){
|
|
| 459 | + protected function getTemplate($name) {
|
|
| 460 | 460 | $out = ''; |
| 461 | - $file = dirname(dirname(__FILE__)).'/tpl/'.$name.'.html'; |
|
| 462 | - if( FS::getInstance()->checkFile($file)){
|
|
| 463 | - $out = '@CODE: '.file_get_contents($file); |
|
| 461 | + $file = dirname(dirname(__FILE__)) . '/tpl/' . $name . '.html'; |
|
| 462 | + if (FS::getInstance()->checkFile($file)) {
|
|
| 463 | + $out = '@CODE: ' . file_get_contents($file); |
|
| 464 | 464 | } |
| 465 | 465 | return $out; |
| 466 | 466 | } |
| 467 | - protected static function loadLang($lang){
|
|
| 468 | - $file = dirname(dirname(__FILE__)).'/lang/'.$lang.'.php'; |
|
| 469 | - if( ! FS::getInstance()->checkFile($file)){
|
|
| 467 | + protected static function loadLang($lang) {
|
|
| 468 | + $file = dirname(dirname(__FILE__)) . '/lang/' . $lang . '.php'; |
|
| 469 | + if (!FS::getInstance()->checkFile($file)) {
|
|
| 470 | 470 | $file = false; |
| 471 | 471 | } |
| 472 | - if(!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)){
|
|
| 472 | + if (!empty($lang) && !isset(static::$langDic[$lang]) && !empty($file)) {
|
|
| 473 | 473 | static::$langDic[$lang] = include_once($file); |
| 474 | - if(is_array(static::$langDic[$lang])){
|
|
| 474 | + if (is_array(static::$langDic[$lang])) {
|
|
| 475 | 475 | static::$langDic[$lang] = APIHelpers::renameKeyArr(static::$langDic[$lang], $lang); |
| 476 | - }else{
|
|
| 476 | + } else {
|
|
| 477 | 477 | static::$langDic[$lang] = array(); |
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | 480 | return !(empty($lang) || empty(static::$langDic[$lang])); |
| 481 | 481 | } |
| 482 | - protected static function getLangMsg($key, $default){
|
|
| 482 | + protected static function getLangMsg($key, $default) {
|
|
| 483 | 483 | $out = $default; |
| 484 | 484 | $lng = static::$lang; |
| 485 | 485 | $dic = static::$langDic; |
| 486 | - if(isset($dic[$lng], $dic[$lng][$lng.'.'.$key])){
|
|
| 487 | - $out = $dic[$lng][$lng.'.'.$key]; |
|
| 486 | + if (isset($dic[$lng], $dic[$lng][$lng . '.' . $key])) {
|
|
| 487 | + $out = $dic[$lng][$lng . '.' . $key]; |
|
| 488 | 488 | } |
| 489 | - if(class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])){
|
|
| 490 | - $msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.'.$key));
|
|
| 491 | - if(!empty($msg)){
|
|
| 489 | + if (class_exists('evoBabel', false) && isset(self::$instance->modx->snippetCache['lang'])) {
|
|
| 490 | + $msg = self::$instance->modx->runSnippet('lang', array('a' => 'DLUsers.' . $key));
|
|
| 491 | + if (!empty($msg)) {
|
|
| 492 | 492 | $out = $msg; |
| 493 | 493 | } |
| 494 | 494 | } |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | * @absctract |
| 26 | 26 | */ |
| 27 | 27 | |
| 28 | - public function getUrl($id = 0) |
|
| 28 | + public function getUrl($id = 0) |
|
| 29 | 29 | {
|
| 30 | - $id = ((int)$id > 0) ? (int)$id : $this->getCurrentMODXPageID(); |
|
| 30 | + $id = ((int)$id > 0) ? (int)$id : $this->getCurrentMODXPageID(); |
|
| 31 | 31 | |
| 32 | 32 | $link = $this->checkExtender('request') ? $this->extender['request']->getLink() : $this->getRequest();
|
| 33 | 33 | if($id == $this->modx->config['site_start']){
|
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | * @var $extPrepare prepare_DL_Extender |
| 85 | 85 | */ |
| 86 | 86 | $extPrepare = $this->getExtender('prepare');
|
| 87 | - $this->skippedDocs = 0; |
|
| 87 | + $this->skippedDocs = 0; |
|
| 88 | 88 | foreach ($this->_docs as $item) {
|
| 89 | 89 | $this->renderTPL = $tpl; |
| 90 | 90 | if ($extUser) {
|
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | $findTpl = $this->renderTPL; |
| 106 | - $tmp = $this->uniformPrepare($item, $i); |
|
| 106 | + $tmp = $this->uniformPrepare($item, $i); |
|
| 107 | 107 | extract($tmp, EXTR_SKIP); |
| 108 | 108 | if ($this->renderTPL == '') {
|
| 109 | 109 | $this->renderTPL = $findTpl; |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | 'nameParam' => 'prepare' |
| 116 | 116 | )); |
| 117 | 117 | if (is_bool($item) && $item === false) {
|
| 118 | - $this->skippedDocs++; |
|
| 118 | + $this->skippedDocs++; |
|
| 119 | 119 | continue; |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -147,13 +147,13 @@ discard block |
||
| 147 | 147 | $extSummary = $this->getExtender('summary');
|
| 148 | 148 | |
| 149 | 149 | /** |
| 150 | - * @var $extPrepare prepare_DL_Extender |
|
| 151 | - */ |
|
| 150 | + * @var $extPrepare prepare_DL_Extender |
|
| 151 | + */ |
|
| 152 | 152 | $extPrepare = $this->getExtender('prepare');
|
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | - * @var $extE e_DL_Extender |
|
| 156 | - */ |
|
| 155 | + * @var $extE e_DL_Extender |
|
| 156 | + */ |
|
| 157 | 157 | $extE = $this->getExtender('e', true, true);
|
| 158 | 158 | |
| 159 | 159 | foreach ($data as $num => $item) {
|
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | case ((array('1') == $fields || in_array('date', $fields)) && $date != 'date'):
|
| 167 | 167 | $tmp = (isset($this->_docs[$num][$date]) && $date != 'createdon' && $this->_docs[$num][$date] != 0 && $this->_docs[$num][$date] == (int)$this->_docs[$num][$date]) ? $this->_docs[$num][$date] : $this->_docs[$num]['createdon']; |
| 168 | 168 | $row['date'] = strftime($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'), $tmp + $this->modx->config['server_offset_time']);
|
| 169 | - // no break |
|
| 169 | + // no break |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | if($extE && $tmp = $extE->init($this, array('data' => $row))){
|
@@ -233,17 +233,17 @@ discard block |
||
| 233 | 233 | if ($sanitarInIDs != "''") {
|
| 234 | 234 | $tmpWhere = "(`{$this->getParentField()}` IN (" . $sanitarInIDs . ")";
|
| 235 | 235 | switch($this->getCFGDef('showParent', '0')){
|
| 236 | - case -1: |
|
| 237 | - $tmpWhere .= ")"; |
|
| 238 | - break; |
|
| 239 | - case 0: |
|
| 240 | - $tmpWhere .= " AND `{$this->getPK()}` NOT IN(" . $sanitarInIDs . "))";
|
|
| 241 | - break; |
|
| 242 | - case 1: |
|
| 243 | - default: |
|
| 244 | - $tmpWhere .= " OR `{$this->getPK()}` IN({$sanitarInIDs}))";
|
|
| 245 | - break; |
|
| 246 | - } |
|
| 236 | + case -1: |
|
| 237 | + $tmpWhere .= ")"; |
|
| 238 | + break; |
|
| 239 | + case 0: |
|
| 240 | + $tmpWhere .= " AND `{$this->getPK()}` NOT IN(" . $sanitarInIDs . "))";
|
|
| 241 | + break; |
|
| 242 | + case 1: |
|
| 243 | + default: |
|
| 244 | + $tmpWhere .= " OR `{$this->getPK()}` IN({$sanitarInIDs}))";
|
|
| 245 | + break; |
|
| 246 | + } |
|
| 247 | 247 | } |
| 248 | 248 | if (($addDocs = $this->getCFGDef('documents', '')) != '') {
|
| 249 | 249 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
@@ -293,18 +293,18 @@ discard block |
||
| 293 | 293 | if ($sanitarInIDs != "''") {
|
| 294 | 294 | switch ($this->getCFGDef('idType', 'parents')) {
|
| 295 | 295 | case 'parents': |
| 296 | - switch($this->getCFGDef('showParent', '0')){
|
|
| 297 | - case '-1': |
|
| 298 | - $tmpWhere = "`{$this->getParentField()}` IN ({$sanitarInIDs})";
|
|
| 299 | - break; |
|
| 300 | - case 0: |
|
| 301 | - $tmpWhere = "`{$this->getParentField()}` IN ({$sanitarInIDs}) AND `{$this->getPK()}` NOT IN({$sanitarInIDs})";
|
|
| 302 | - break; |
|
| 303 | - case 1: |
|
| 304 | - default: |
|
| 305 | - $tmpWhere = "(`{$this->getParentField()}` IN ({$sanitarInIDs}) OR `{$this->getPK()}` IN({$sanitarInIDs}))";
|
|
| 306 | - break; |
|
| 307 | - } |
|
| 296 | + switch($this->getCFGDef('showParent', '0')){
|
|
| 297 | + case '-1': |
|
| 298 | + $tmpWhere = "`{$this->getParentField()}` IN ({$sanitarInIDs})";
|
|
| 299 | + break; |
|
| 300 | + case 0: |
|
| 301 | + $tmpWhere = "`{$this->getParentField()}` IN ({$sanitarInIDs}) AND `{$this->getPK()}` NOT IN({$sanitarInIDs})";
|
|
| 302 | + break; |
|
| 303 | + case 1: |
|
| 304 | + default: |
|
| 305 | + $tmpWhere = "(`{$this->getParentField()}` IN ({$sanitarInIDs}) OR `{$this->getPK()}` IN({$sanitarInIDs}))";
|
|
| 306 | + break; |
|
| 307 | + } |
|
| 308 | 308 | if (($addDocs = $this->getCFGDef('documents', '')) != '') {
|
| 309 | 309 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
| 310 | 310 | $where[] = "((" . $tmpWhere . ") OR `{$this->getPK()}` IN({$addDocs}))";
|
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $comments = $extJotCount->countComments(array_keys($this->_docs)); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - $this->skippedDocs = 0; |
|
| 139 | + $this->skippedDocs = 0; |
|
| 140 | 140 | foreach ($this->_docs as $item) {
|
| 141 | 141 | $this->renderTPL = $tpl; |
| 142 | 142 | if ($extUser) {
|
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | |
| 171 | 171 | $findTpl = $this->renderTPL; |
| 172 | 172 | $tmp = $this->uniformPrepare($item, $i); |
| 173 | - extract($tmp, EXTR_SKIP); |
|
| 173 | + extract($tmp, EXTR_SKIP); |
|
| 174 | 174 | if ($this->renderTPL == '') {
|
| 175 | 175 | $this->renderTPL = $findTpl; |
| 176 | 176 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | 'nameParam' => 'prepare' |
| 182 | 182 | )); |
| 183 | 183 | if (is_bool($item) && $item === false) {
|
| 184 | - $this->skippedDocs++; |
|
| 184 | + $this->skippedDocs++; |
|
| 185 | 185 | continue; |
| 186 | 186 | } |
| 187 | 187 | } |
@@ -217,13 +217,13 @@ discard block |
||
| 217 | 217 | $extSummary = $this->getExtender('summary');
|
| 218 | 218 | |
| 219 | 219 | /** |
| 220 | - * @var $extPrepare prepare_DL_Extender |
|
| 221 | - */ |
|
| 220 | + * @var $extPrepare prepare_DL_Extender |
|
| 221 | + */ |
|
| 222 | 222 | $extPrepare = $this->getExtender('prepare');
|
| 223 | 223 | |
| 224 | 224 | /** |
| 225 | - * @var $extE e_DL_Extender |
|
| 226 | - */ |
|
| 225 | + * @var $extE e_DL_Extender |
|
| 226 | + */ |
|
| 227 | 227 | $extE = $this->getExtender('e', true, true);
|
| 228 | 228 | |
| 229 | 229 | foreach ($data as $num => $item) {
|
@@ -231,11 +231,11 @@ discard block |
||
| 231 | 231 | switch (true) {
|
| 232 | 232 | case ((array('1') == $fields || in_array('summary', $fields)) && $extSummary):
|
| 233 | 233 | $row['summary'] = $this->getSummary($this->_docs[$num], $extSummary, 'introtext', 'content'); |
| 234 | - // no break |
|
| 234 | + // no break |
|
| 235 | 235 | case (array('1') == $fields || in_array('date', $fields)):
|
| 236 | 236 | $tmp = (isset($this->_docs[$num][$date]) && $date != 'createdon' && $this->_docs[$num][$date] != 0 && $this->_docs[$num][$date] == (int)$this->_docs[$num][$date]) ? $this->_docs[$num][$date] : $this->_docs[$num]['createdon']; |
| 237 | 237 | $row['date'] = strftime($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'), $tmp + $this->modx->config['server_offset_time']);
|
| 238 | - // no break |
|
| 238 | + // no break |
|
| 239 | 239 | case (array('1') == $fields || in_array(array('menutitle', 'pagetitle'), $fields)):
|
| 240 | 240 | $row['title'] = ($row['menutitle'] == '' ? $row['pagetitle'] : $row['menutitle']); |
| 241 | 241 | case ((array('1') == $fields || in_array(array('content', 'type'), $fields)) && $this->getCFGDef('makeUrl', 1)):
|
@@ -292,18 +292,18 @@ discard block |
||
| 292 | 292 | if ($sanitarInIDs != "''") {
|
| 293 | 293 | switch ($this->getCFGDef('idType', 'parents')) {
|
| 294 | 294 | case 'parents': |
| 295 | - switch($this->getCFGDef('showParent', '0')){
|
|
| 296 | - case '-1': |
|
| 297 | - $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
|
|
| 298 | - break; |
|
| 299 | - case 0: |
|
| 300 | - $tmpWhere = "c.parent IN ({$sanitarInIDs}) AND c.id NOT IN({$sanitarInIDs})";
|
|
| 301 | - break; |
|
| 302 | - case 1: |
|
| 303 | - default: |
|
| 304 | - $tmpWhere = "(c.parent IN ({$sanitarInIDs}) OR c.id IN({$sanitarInIDs}))";
|
|
| 305 | - break; |
|
| 306 | - } |
|
| 295 | + switch($this->getCFGDef('showParent', '0')){
|
|
| 296 | + case '-1': |
|
| 297 | + $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
|
|
| 298 | + break; |
|
| 299 | + case 0: |
|
| 300 | + $tmpWhere = "c.parent IN ({$sanitarInIDs}) AND c.id NOT IN({$sanitarInIDs})";
|
|
| 301 | + break; |
|
| 302 | + case 1: |
|
| 303 | + default: |
|
| 304 | + $tmpWhere = "(c.parent IN ({$sanitarInIDs}) OR c.id IN({$sanitarInIDs}))";
|
|
| 305 | + break; |
|
| 306 | + } |
|
| 307 | 307 | if (($addDocs = $this->getCFGDef('documents', '')) != '') {
|
| 308 | 308 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
| 309 | 309 | $whereArr[] = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))";
|
@@ -459,17 +459,17 @@ discard block |
||
| 459 | 459 | $tmpWhere = null; |
| 460 | 460 | if ($sanitarInIDs != "''") {
|
| 461 | 461 | switch($this->getCFGDef('showParent', '0')){
|
| 462 | - case '-1': |
|
| 463 | - $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
|
|
| 464 | - break; |
|
| 465 | - case 0: |
|
| 466 | - $tmpWhere = "c.parent IN (" . $sanitarInIDs . ") AND c.id NOT IN(" . $sanitarInIDs . ")";
|
|
| 467 | - break; |
|
| 468 | - case 1: |
|
| 469 | - default: |
|
| 470 | - $tmpWhere = "(c.parent IN (" . $sanitarInIDs . ") OR c.id IN({$sanitarInIDs}))";
|
|
| 471 | - break; |
|
| 472 | - } |
|
| 462 | + case '-1': |
|
| 463 | + $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
|
|
| 464 | + break; |
|
| 465 | + case 0: |
|
| 466 | + $tmpWhere = "c.parent IN (" . $sanitarInIDs . ") AND c.id NOT IN(" . $sanitarInIDs . ")";
|
|
| 467 | + break; |
|
| 468 | + case 1: |
|
| 469 | + default: |
|
| 470 | + $tmpWhere = "(c.parent IN (" . $sanitarInIDs . ") OR c.id IN({$sanitarInIDs}))";
|
|
| 471 | + break; |
|
| 472 | + } |
|
| 473 | 473 | } |
| 474 | 474 | if (($addDocs = $this->getCFGDef('documents', '')) != '') {
|
| 475 | 475 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | $extPrepare = $this->getExtender('prepare');
|
| 73 | 73 | |
| 74 | - /** |
|
| 74 | + /** |
|
| 75 | 75 | * @var $extJotCount jotcount_DL_Extender |
| 76 | 76 | */ |
| 77 | 77 | $extJotCount = $this->getCFGdef('jotcount', 0) ? $this->getExtender('jotcount', true) : NULL;
|
@@ -80,41 +80,41 @@ discard block |
||
| 80 | 80 | $comments = $extJotCount->countComments(array_keys($this->_docs)); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - $this->skippedDocs = 0; |
|
| 83 | + $this->skippedDocs = 0; |
|
| 84 | 84 | foreach ($this->_docs as $item) {
|
| 85 | - $this->renderTPL = $tpl; |
|
| 85 | + $this->renderTPL = $tpl; |
|
| 86 | 86 | if ($extUser) {
|
| 87 | 87 | $item = $extUser->setUserData($item); //[+user.id.createdby+], [+user.fullname.publishedby+], [+dl.user.publishedby+].... |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | $item['summary'] = $extSummary ? $this->getSummary($item, $extSummary, '', 'content') : ''; |
| 91 | 91 | |
| 92 | - if ($extJotCount) {
|
|
| 92 | + if ($extJotCount) {
|
|
| 93 | 93 | $item['jotcount'] = APIHelpers::getkey($comments, $item['id'], 0); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | $item = array_merge($item, $sysPlh); //inside the chunks available all placeholders set via $modx->toPlaceholders with prefix id, and with prefix sysKey |
| 97 | - $item['iteration'] = $i; //[+iteration+] - Number element. Starting from zero |
|
| 97 | + $item['iteration'] = $i; //[+iteration+] - Number element. Starting from zero |
|
| 98 | 98 | |
| 99 | 99 | if($this->getCFGDef('makeUrl', 1)){
|
| 100 | - if($item['type'] == 'reference'){
|
|
| 101 | - $item['url'] = is_numeric($item['content']) ? $this->modx->makeUrl($item['content'], '', '', $this->getCFGDef('urlScheme', '')) : $item['content'];
|
|
| 102 | - }else{
|
|
| 103 | - $item['url'] = $this->modx->makeUrl($item['id'], '', '', $this->getCFGDef('urlScheme', ''));
|
|
| 104 | - } |
|
| 105 | - } |
|
| 100 | + if($item['type'] == 'reference'){
|
|
| 101 | + $item['url'] = is_numeric($item['content']) ? $this->modx->makeUrl($item['content'], '', '', $this->getCFGDef('urlScheme', '')) : $item['content'];
|
|
| 102 | + }else{
|
|
| 103 | + $item['url'] = $this->modx->makeUrl($item['id'], '', '', $this->getCFGDef('urlScheme', ''));
|
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | 107 | $item['date'] = $item['createdon'] + $this->modx->config['server_offset_time']; |
| 108 | 108 | if ($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M') != '') {
|
| 109 | 109 | $item['date'] = strftime($this->getCFGDef('dateFormat', '%d.%b.%y %H:%M'), $item['date']);
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - $findTpl = $this->renderTPL; |
|
| 113 | - $tmp = $this->uniformPrepare($item, $i); |
|
| 114 | - extract($tmp, EXTR_SKIP); |
|
| 115 | - if ($this->renderTPL == '') {
|
|
| 116 | - $this->renderTPL = $findTpl; |
|
| 117 | - } |
|
| 112 | + $findTpl = $this->renderTPL; |
|
| 113 | + $tmp = $this->uniformPrepare($item, $i); |
|
| 114 | + extract($tmp, EXTR_SKIP); |
|
| 115 | + if ($this->renderTPL == '') {
|
|
| 116 | + $this->renderTPL = $findTpl; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | 119 | if ($extPrepare) {
|
| 120 | 120 | $item = $extPrepare->init($this, array( |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | 'nameParam' => 'prepare' |
| 123 | 123 | )); |
| 124 | 124 | if (is_bool($item) && $item === false) {
|
| 125 | - $this->skippedDocs++; |
|
| 125 | + $this->skippedDocs++; |
|
| 126 | 126 | continue; |
| 127 | 127 | } |
| 128 | 128 | } |
@@ -175,18 +175,18 @@ discard block |
||
| 175 | 175 | if ($sanitarInIDs != "''") {
|
| 176 | 176 | switch ($this->getCFGDef('idType', 'parents')) {
|
| 177 | 177 | case 'parents': |
| 178 | - switch($this->getCFGDef('showParent', '0')){
|
|
| 179 | - case '-1': |
|
| 180 | - $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
|
|
| 181 | - break; |
|
| 182 | - case 0: |
|
| 183 | - $tmpWhere = "c.parent IN ({$sanitarInIDs}) AND c.id NOT IN({$sanitarInIDs})";
|
|
| 184 | - break; |
|
| 185 | - case 1: |
|
| 186 | - default: |
|
| 187 | - $tmpWhere = "(c.parent IN ({$sanitarInIDs}) OR c.id IN({$sanitarInIDs}))";
|
|
| 188 | - break; |
|
| 189 | - } |
|
| 178 | + switch($this->getCFGDef('showParent', '0')){
|
|
| 179 | + case '-1': |
|
| 180 | + $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
|
|
| 181 | + break; |
|
| 182 | + case 0: |
|
| 183 | + $tmpWhere = "c.parent IN ({$sanitarInIDs}) AND c.id NOT IN({$sanitarInIDs})";
|
|
| 184 | + break; |
|
| 185 | + case 1: |
|
| 186 | + default: |
|
| 187 | + $tmpWhere = "(c.parent IN ({$sanitarInIDs}) OR c.id IN({$sanitarInIDs}))";
|
|
| 188 | + break; |
|
| 189 | + } |
|
| 190 | 190 | if (($addDocs = $this->getCFGDef('documents', '')) != '') {
|
| 191 | 191 | $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
| 192 | 192 | $whereArr[] = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))";
|
@@ -301,19 +301,19 @@ discard block |
||
| 301 | 301 | |
| 302 | 302 | protected function getChildrenList() |
| 303 | 303 | {
|
| 304 | - $where = array(); |
|
| 305 | - $out = array(); |
|
| 304 | + $where = array(); |
|
| 305 | + $out = array(); |
|
| 306 | 306 | |
| 307 | - $tmpWhere = $this->getCFGDef('addWhereList', '');
|
|
| 308 | - $tmpWhere = sqlHelper::trimLogicalOp($tmpWhere); |
|
| 309 | - if (!empty($tmpWhere)) {
|
|
| 310 | - $where[] = $tmpWhere; |
|
| 311 | - } |
|
| 307 | + $tmpWhere = $this->getCFGDef('addWhereList', '');
|
|
| 308 | + $tmpWhere = sqlHelper::trimLogicalOp($tmpWhere); |
|
| 309 | + if (!empty($tmpWhere)) {
|
|
| 310 | + $where[] = $tmpWhere; |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - $tmpWhere = sqlHelper::trimLogicalOp($this->_filters['where']); |
|
| 314 | - if (!empty($tmpWhere)) {
|
|
| 315 | - $where[] = $tmpWhere; |
|
| 316 | - } |
|
| 313 | + $tmpWhere = sqlHelper::trimLogicalOp($this->_filters['where']); |
|
| 314 | + if (!empty($tmpWhere)) {
|
|
| 315 | + $where[] = $tmpWhere; |
|
| 316 | + } |
|
| 317 | 317 | |
| 318 | 318 | $tbl_site_content = $this->getTable('catalog', 'c');
|
| 319 | 319 | |
@@ -323,53 +323,53 @@ discard block |
||
| 323 | 323 | |
| 324 | 324 | $tmpWhere = null; |
| 325 | 325 | |
| 326 | - if ($sanitarInIDs != "''") {
|
|
| 327 | - switch($this->getCFGDef('showParent', '0')){
|
|
| 328 | - case '-1': |
|
| 329 | - $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
|
|
| 330 | - break; |
|
| 331 | - case 0: |
|
| 332 | - $tmpWhere = "c.parent IN (" . $sanitarInIDs . ") AND c.id NOT IN(" . $sanitarInIDs . ")";
|
|
| 333 | - break; |
|
| 334 | - case 1: |
|
| 335 | - default: |
|
| 336 | - $tmpWhere = "(c.parent IN (" . $sanitarInIDs . ") OR c.id IN({$sanitarInIDs}))";
|
|
| 337 | - break; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - if (($addDocs = $this->getCFGDef('documents', '')) != '') {
|
|
| 341 | - $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
|
| 342 | - if(empty($tmpWhere)){
|
|
| 343 | - $tmpWhere = "c.id IN({$addDocs})";
|
|
| 344 | - }else{
|
|
| 345 | - $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))";
|
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - if (!empty($tmpWhere)) {
|
|
| 349 | - $where[] = $tmpWhere; |
|
| 350 | - } |
|
| 351 | - if (!$this->getCFGDef('showNoPublish', 0)) {
|
|
| 352 | - $where[] = "c.published=1"; |
|
| 353 | - } |
|
| 354 | - if (!empty($where)) {
|
|
| 355 | - $where = "WHERE " . implode(" AND ", $where);
|
|
| 356 | - } else {
|
|
| 357 | - $where = ''; |
|
| 358 | - } |
|
| 326 | + if ($sanitarInIDs != "''") {
|
|
| 327 | + switch($this->getCFGDef('showParent', '0')){
|
|
| 328 | + case '-1': |
|
| 329 | + $tmpWhere = "c.parent IN (" . $sanitarInIDs . ")";
|
|
| 330 | + break; |
|
| 331 | + case 0: |
|
| 332 | + $tmpWhere = "c.parent IN (" . $sanitarInIDs . ") AND c.id NOT IN(" . $sanitarInIDs . ")";
|
|
| 333 | + break; |
|
| 334 | + case 1: |
|
| 335 | + default: |
|
| 336 | + $tmpWhere = "(c.parent IN (" . $sanitarInIDs . ") OR c.id IN({$sanitarInIDs}))";
|
|
| 337 | + break; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + if (($addDocs = $this->getCFGDef('documents', '')) != '') {
|
|
| 341 | + $addDocs = $this->sanitarIn($this->cleanIDs($addDocs)); |
|
| 342 | + if(empty($tmpWhere)){
|
|
| 343 | + $tmpWhere = "c.id IN({$addDocs})";
|
|
| 344 | + }else{
|
|
| 345 | + $tmpWhere = "((" . $tmpWhere . ") OR c.id IN({$addDocs}))";
|
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + if (!empty($tmpWhere)) {
|
|
| 349 | + $where[] = $tmpWhere; |
|
| 350 | + } |
|
| 351 | + if (!$this->getCFGDef('showNoPublish', 0)) {
|
|
| 352 | + $where[] = "c.published=1"; |
|
| 353 | + } |
|
| 354 | + if (!empty($where)) {
|
|
| 355 | + $where = "WHERE " . implode(" AND ", $where);
|
|
| 356 | + } else {
|
|
| 357 | + $where = ''; |
|
| 358 | + } |
|
| 359 | 359 | $fields = $this->getCFGDef('selectFields', 'c.*');
|
| 360 | - $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id'));
|
|
| 361 | - if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
|
|
| 362 | - $sql = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " .
|
|
| 363 | - $group . " ". |
|
| 364 | - $sort . " " . |
|
| 365 | - $this->LimitSQL($this->getCFGDef('queryLimit', 0))
|
|
| 366 | - ); |
|
| 367 | - |
|
| 368 | - $rows = $this->modx->db->makeArray($sql); |
|
| 369 | - foreach ($rows as $item) {
|
|
| 370 | - $out[$item['id']] = $item; |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - return $out; |
|
| 360 | + $group = $this->getGroupSQL($this->getCFGDef('groupBy', 'c.id'));
|
|
| 361 | + if ($sanitarInIDs != "''" || $this->getCFGDef('ignoreEmpty', '0')) {
|
|
| 362 | + $sql = $this->dbQuery("SELECT {$fields} FROM " . $from . " " . $where . " " .
|
|
| 363 | + $group . " ". |
|
| 364 | + $sort . " " . |
|
| 365 | + $this->LimitSQL($this->getCFGDef('queryLimit', 0))
|
|
| 366 | + ); |
|
| 367 | + |
|
| 368 | + $rows = $this->modx->db->makeArray($sql); |
|
| 369 | + foreach ($rows as $item) {
|
|
| 370 | + $out[$item['id']] = $item; |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + return $out; |
|
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | \ No newline at end of file |
@@ -99,7 +99,9 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | break; |
| 101 | 101 | case '@CHUNK': |
| 102 | - if ($subTmp != '') $tpl = $this->modx->getChunk($subTmp); |
|
| 102 | + if ($subTmp != '') {
|
|
| 103 | + $tpl = $this->modx->getChunk($subTmp); |
|
| 104 | + } |
|
| 103 | 105 | break; |
| 104 | 106 | case '@INLINE': |
| 105 | 107 | case '@TPL': |
@@ -120,15 +122,21 @@ discard block |
||
| 120 | 122 | break; |
| 121 | 123 | case '@PLH': |
| 122 | 124 | case '@PLACEHOLDER': |
| 123 | - if ($subTmp != '') $tpl = $this->modx->getPlaceholder($subTmp); |
|
| 125 | + if ($subTmp != '') {
|
|
| 126 | + $tpl = $this->modx->getPlaceholder($subTmp); |
|
| 127 | + } |
|
| 124 | 128 | break; |
| 125 | 129 | case '@CFG': |
| 126 | 130 | case '@CONFIG': |
| 127 | 131 | case '@OPTIONS': |
| 128 | - if ($subTmp != '') $tpl = $this->modx->getConfig($subTmp); |
|
| 132 | + if ($subTmp != '') {
|
|
| 133 | + $tpl = $this->modx->getConfig($subTmp); |
|
| 134 | + } |
|
| 129 | 135 | break; |
| 130 | 136 | case '@SNIPPET': |
| 131 | - if ($subTmp != '') $tpl = $this->modx->runSnippet($subTmp, $this->modx->event->params); |
|
| 137 | + if ($subTmp != '') {
|
|
| 138 | + $tpl = $this->modx->runSnippet($subTmp, $this->modx->event->params); |
|
| 139 | + } |
|
| 132 | 140 | break; |
| 133 | 141 | case '@RENDERPAGE': |
| 134 | 142 | $tpl = $this->renderDoc($subTmp, false); |
@@ -166,7 +174,9 @@ discard block |
||
| 166 | 174 | * - оригинальный экземпляр класса DocumentParser |
| 167 | 175 | */ |
| 168 | 176 | public function renderDoc($id, $events = false, $tpl = null){
|
| 169 | - if((int)$id <= 0) return ''; |
|
| 177 | + if((int)$id <= 0) {
|
|
| 178 | + return ''; |
|
| 179 | + } |
|
| 170 | 180 | |
| 171 | 181 | $m = clone $this->modx; //Чтобы была возможность вызывать события |
| 172 | 182 | $m->documentObject = $m->getDocumentObject('id', (int)$id , $events ? 'prepareResponse' : null);
|
@@ -313,7 +323,7 @@ discard block |
||
| 313 | 323 | } |
| 314 | 324 | if($i <= $minPasses || $out != $html){
|
| 315 | 325 | $out = $modx->parseDocumentSource($out); |
| 316 | - }else{
|
|
| 326 | + } else{
|
|
| 317 | 327 | break; |
| 318 | 328 | } |
| 319 | 329 | } |