render.func.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * The render function file of zin 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 Hao Sun <sunhao@easycorp.ltd>
  8. * @package zin
  9. * @link https://www.zentao.net
  10. */
  11. namespace zin;
  12. require_once __DIR__ . DS . 'zin.class.php';
  13. /**
  14. * 设置渲染目标所使用的部件名称。
  15. * Set render widget name for target.
  16. *
  17. * @param string $wgName
  18. * @param string $target
  19. * @return void
  20. */
  21. function render($wgName = '', $target = 'all')
  22. {
  23. if(!$wgName) return;
  24. if(is_array($wgName))
  25. {
  26. context()->setRenderWgMap($wgName);
  27. return;
  28. }
  29. context()->setRenderWgMap($target, $wgName);
  30. }
  31. /**
  32. * 将视图页面声明的所有内容通过一个部件进行渲染,并输出 HTML。
  33. * Render page content with a widget to HTML.
  34. *
  35. * @access public
  36. * @param array $options
  37. * @return void
  38. */
  39. function renderPage($options = array())
  40. {
  41. /* 获取全局渲染部件实例和指令。 Get global render widgets and directives. */
  42. $context = context();
  43. $globalItems = $context->getGlobalRenderList();
  44. $wgName = $context->getRenderWgName();
  45. /* 判断是否渲染为完整页面。 Check if render in full page. */
  46. $isFullPage = str_starts_with($wgName, 'page');
  47. if($isFullPage) $globalItems[] = set::display(false);
  48. /* 获取部件渲染选项。 Get widget display options. */
  49. if(empty($options) && isset($_SERVER['HTTP_X_ZIN_OPTIONS']) && !empty($_SERVER['HTTP_X_ZIN_OPTIONS']))
  50. {
  51. $setting = $_SERVER['HTTP_X_ZIN_OPTIONS'];
  52. $options = $setting[0] === '{' ? json_decode($setting, true) : array('selector' => $setting);
  53. }
  54. /* 创建部件实例。 Create widget instance. */
  55. $wg = createWg($wgName, $globalItems);
  56. /* 如果不是渲染一个完整页面,则使用 fragment 进行渲染。 If not render in full page, then render all items in a fragment. */
  57. if(!$isFullPage && $wgName !== 'fragment') $wg = fragment($wg);
  58. /* 渲染并输出 HTML。 Render and display html. */
  59. $html = $context->render($wg, zget($options, 'selector', null), zget($options, 'type', 'html'));
  60. ob_start();
  61. echo $html;
  62. }