zin.func.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * The node function file of zin module of ZenTaoPMS.
  4. *
  5. * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
  6. * @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
  7. * @author sunhao<sunhao@easycorp.ltd>
  8. * @package zin
  9. * @link http://www.zentao.net
  10. */
  11. namespace zin;
  12. require_once dirname(__DIR__) . DS . 'utils' . DS . 'flat.func.php';
  13. require_once __DIR__ . DS . 'loader.func.php';
  14. require_once __DIR__ . DS . 'node.class.php';
  15. require_once __DIR__ . DS . 'text.class.php';
  16. require_once __DIR__ . DS . 'htm.class.php';
  17. require_once __DIR__ . DS . 'props.class.php';
  18. require_once __DIR__ . DS . 'directive.class.php';
  19. require_once __DIR__ . DS . 'setting.class.php';
  20. require_once __DIR__ . DS . 'set.class.php';
  21. require_once __DIR__ . DS . 'wg.class.php';
  22. require_once __DIR__ . DS . 'h.class.php';
  23. require_once __DIR__ . DS . 'h.func.php';
  24. require_once __DIR__ . DS . 'item.class.php';
  25. require_once __DIR__ . DS . 'to.class.php';
  26. require_once __DIR__ . DS . 'context.func.php';
  27. require_once __DIR__ . DS . 'query.class.php';
  28. require_once __DIR__ . DS . 'on.class.php';
  29. require_once __DIR__ . DS . 'jquery.class.php';
  30. require_once __DIR__ . DS . 'style.class.php';
  31. /**
  32. * Create block content.
  33. *
  34. * @param string $name
  35. * @param mixed ...$args
  36. * @return directive
  37. */
  38. function to($blockName, ...$args)
  39. {
  40. skipRenderInGlobal($args);
  41. return directive('block', array($blockName => $args));
  42. }
  43. /**
  44. * Create content for block "before".
  45. *
  46. * @param mixed $args
  47. * @return directive
  48. */
  49. function before(...$args)
  50. {
  51. return to('before', ...$args);
  52. }
  53. /**
  54. * Create content for block "after".
  55. *
  56. * @param mixed $args
  57. * @return directive
  58. */
  59. function after(...$args)
  60. {
  61. return to('after', ...$args);
  62. }
  63. /**
  64. * Create node contents inherited from the given node.
  65. *
  66. * @param node|array $item
  67. * @return array
  68. */
  69. function inherit($item)
  70. {
  71. if(!($item instanceof node)) $item = new node($item);
  72. return array(set($item->props->toJSON()), directive('block', $item->blocks), $item->children());
  73. }
  74. /**
  75. * Divorce node from parent.
  76. *
  77. * @param node|array $item
  78. * @return array
  79. */
  80. function divorce($item)
  81. {
  82. if($item instanceof node)
  83. {
  84. $item->parent = null;
  85. }
  86. else if(is_array($item))
  87. {
  88. foreach($item as $i) divorce($i);
  89. }
  90. return $item;
  91. }
  92. /**
  93. * Group nodes by type.
  94. *
  95. * @param node|array $items
  96. * @param string $types
  97. * @return array
  98. */
  99. function groupWgInList($items, $types)
  100. {
  101. if(is_string($types)) $types = explode(',', $types);
  102. $typesMap = array();
  103. $restList = array();
  104. foreach($types as $type) $typesMap[$type] = array();
  105. foreach($items as $item)
  106. {
  107. if(!($item instanceof node)) continue;
  108. $type = $item->type();
  109. if(isset($typesMap[$type])) $typesMap[$type][] = $item;
  110. else $restList[] = $item;
  111. }
  112. $groups = array();
  113. foreach($types as $index => $type) $groups[] = $typesMap[$type];
  114. $groups[] = $restList;
  115. return $groups;
  116. }