/assets/snippets/DocLister/lib/DLFixedPrepare.class.php

https://github.com/dmi3yy/modx.evo.custom · PHP · 126 lines · 98 code · 11 blank · 17 comment · 29 complexity · ebe46c77fd6ff8e1be5d5cbaec7be451 MD5 · raw file

  1. <?php
  2. if (!class_exists("DLFixedPrepare", false)) {
  3. /**
  4. * Class DLFixedPrepare
  5. */
  6. class DLFixedPrepare
  7. {
  8. /**
  9. * @param array $data
  10. * @param DocumentParser $modx
  11. * @param $_DL
  12. * @param prepare_DL_Extender $_eDL
  13. * @return array
  14. */
  15. public static function buildMenu(array $data = array(), DocumentParser $modx, $_DL, prepare_DL_Extender $_eDL)
  16. {
  17. $params = $_DL->getCFGDef('params', array());
  18. if ($_DL->getCfgDef('currentDepth', 1) < $_DL->getCFGDef('maxDepth', 5)) {
  19. $params['currentDepth'] = $_DL->getCfgDef('currentDepth', 1) + 1;
  20. $params['parents'] = $data['id'];
  21. $params['idType'] = 'parents';
  22. $params['documents'] = '';
  23. $data['dl.submenu'] = ($data['isfolder']) ? $modx->runSnippet('DLBuildMenu', $params) : '';
  24. } else {
  25. $data['dl.submenu'] = '';
  26. }
  27. $data['dl.currentDepth'] = $_DL->getCfgDef('currentDepth', 1);
  28. if (($parentIDs = $_eDL->getStore('parentIDs')) === null) {
  29. $parentIDs = array_values($modx->getParentIds($modx->documentObject['id']));
  30. $_eDL->setStore('parentIDs', $parentIDs);
  31. }
  32. $isActive = ((is_array($parentIDs) && in_array($data['id'],
  33. $parentIDs)) || $data['id'] == $modx->documentObject['id']);
  34. $activeClass = $_DL->getCfgDef('activeClass', 'active');
  35. if ($isActive) {
  36. $data['dl.class'] .= ' ' . $activeClass;
  37. }
  38. if (strpos($data['dl.class'], 'current') !== false && strpos($data['dl.class'],
  39. ' ' . $activeClass) === false
  40. ) {
  41. $data['dl.class'] = str_replace('current', 'current ' . $activeClass, $data['dl.class']);
  42. }
  43. $tpl = empty($data['dl.submenu']) ? 'noChildrenRowTPL' : 'mainRowTpl';
  44. $_DL->renderTPL = $_DL->getCfgDef($tpl);
  45. if (strpos($data['dl.class'], 'current') !== false) {
  46. $_DL->renderTPL = $_DL->getCfgDef('TplCurrent', $_DL->renderTPL);
  47. $_DL->renderTPL = $_DL->getCfgDef('TplCurrent' . $data['dl.currentDepth'], $_DL->renderTPL);
  48. if (empty($data['dl.submenu'])) {
  49. $_DL->renderTPL = $_DL->getCfgDef('TplCurrentNoChildren' . $data['dl.currentDepth'],
  50. $_DL->renderTPL);
  51. }
  52. }
  53. return $data;
  54. }
  55. /**
  56. * @param array $data
  57. * @param DocumentParser $modx
  58. * @param DocLister $_DocLister
  59. * @param prepare_DL_Extender $_extDocLister
  60. * @return array
  61. */
  62. public static function firstChar(
  63. array $data = array(),
  64. DocumentParser $modx,
  65. DocLister $_DocLister,
  66. prepare_DL_Extender $_extDocLister
  67. ) {
  68. $char = mb_substr($data['pagetitle'], 0, 1, 'UTF-8');
  69. $oldChar = $_extDocLister->getStore('char');
  70. if ($oldChar !== $char) {
  71. $sanitarInIDs = $_DocLister->sanitarIn($_DocLister->getIDs());
  72. $where = sqlHelper::trimLogicalOp($_DocLister->getCFGDef('addWhereList', ''));
  73. $where = sqlHelper::trimLogicalOp(($where ? $where . ' AND ' : '') . $_DocLister->filtersWhere());
  74. $where = sqlHelper::trimLogicalOp(($where ? $where . ' AND ' : '') . "SUBSTRING(c.pagetitle,1,1) = '" . $modx->db->escape($char) . "'");
  75. if ($_DocLister->getCFGDef('idType', 'parents') == 'parents') {
  76. if ($where != '') {
  77. $where .= " AND ";
  78. }
  79. $where = "WHERE {$where} c.parent IN (" . $sanitarInIDs . ")";
  80. if (!$_DocLister->getCFGDef('showNoPublish', 0)) {
  81. $where .= " AND c.deleted=0 AND c.published=1";
  82. }
  83. } else {
  84. if ($sanitarInIDs != "''") {
  85. $where .= ($where ? " AND " : "") . "c.id IN ({$sanitarInIDs}) AND";
  86. }
  87. $where = sqlHelper::trimLogicalOp($where);
  88. if ($_DocLister->getCFGDef('showNoPublish', 0)) {
  89. if ($where != '') {
  90. $where = "WHERE {$where}";
  91. }
  92. } else {
  93. if ($where != '') {
  94. $where = "WHERE {$where} AND ";
  95. } else {
  96. $where = "WHERE {$where} ";
  97. }
  98. $where .= "c.deleted=0 AND c.published=1";
  99. }
  100. }
  101. $q = $_DocLister->dbQuery("SELECT count(c.id) as total FROM " . $_DocLister->getTable('site_content',
  102. 'c') . " " . $where);
  103. $total = $modx->db->getValue($q);
  104. $data['OnNewChar'] = $_DocLister->parseChunk($_DocLister->getCFGDef('tplOnNewChar'),
  105. compact("char", "total"));
  106. $_extDocLister->setStore('char', $char);
  107. if ($oldChar !== null) {
  108. $data['CharSeparator'] = $_DocLister->parseChunk($_DocLister->getCFGDef('tplCharSeparator'),
  109. compact("char", "total"));
  110. }
  111. }
  112. return $data;
  113. }
  114. }
  115. }