国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.1KB

  1. <?php if (!defined('DEDEINC')) exit("Request Error!");
  2. /**
  3. * 自定义表单解析类
  4. *
  5. * @version $Id: diyform.cls.php 1 10:31 2010年7月6日Z tianya $
  6. * @package DedeBIZ.Libraries
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once DEDEINC . '/dedetag.class.php';
  12. require_once DEDEINC . '/customfields.func.php';
  13. /**
  14. * diyform
  15. *
  16. * @package diyform
  17. * @subpackage DedeBIZ.Libraries
  18. * @link https://www.dedebiz.com
  19. */
  20. class diyform
  21. {
  22. var $diyid;
  23. var $db;
  24. var $info;
  25. var $name;
  26. var $table;
  27. var $public;
  28. var $listTemplate;
  29. var $viewTemplate;
  30. var $postTemplate;
  31. function diyform($diyid)
  32. {
  33. $this->__construct($diyid);
  34. }
  35. /**
  36. * 析构函数
  37. *
  38. * @access public
  39. * @param string $diyid 自定义表单ID
  40. * @return string
  41. */
  42. function __construct($diyid)
  43. {
  44. $this->diyid = $diyid;
  45. $this->db = $GLOBALS['dsql'];
  46. $query = "SELECT * FROM #@__diyforms WHERE diyid='{$diyid}'";
  47. $diyinfo = $this->db->GetOne($query);
  48. if (!is_array($diyinfo)) {
  49. showMsg('参数不正确,该自定义表单不存在', 'javascript:;');
  50. exit();
  51. }
  52. $this->info = $diyinfo['info'];
  53. $this->name = $diyinfo['name'];
  54. $this->table = $diyinfo['table'];
  55. $this->public = $diyinfo['public'];
  56. $this->listTemplate = $diyinfo['listtemplate'] != '' && file_exists(DEDETEMPLATE . '/plus/' . $diyinfo['listtemplate']) ? $diyinfo['listtemplate'] : 'list_diyform.htm';
  57. $this->viewTemplate = $diyinfo['viewtemplate'] != '' && file_exists(DEDETEMPLATE . '/plus/' . $diyinfo['viewtemplate']) ? $diyinfo['viewtemplate'] : 'view_diyform.htm';;
  58. $this->postTemplate = $diyinfo['posttemplate'] != '' && file_exists(DEDETEMPLATE . '/plus/' . $diyinfo['posttemplate']) ? $diyinfo['posttemplate'] : 'post_diyform.htm';;
  59. }
  60. /**
  61. * 获取表单
  62. *
  63. * @access public
  64. * @param string $type 类型
  65. * @param string $value 值
  66. * @param string $admintype 管理类型
  67. * @return string
  68. */
  69. function getForm($type = 'post', $value = '', $admintype = 'diy')
  70. {
  71. global $cfg_cookie_encode;
  72. $dtp = new DedeTagParse();
  73. $dtp->SetNameSpace("field", "<", ">");
  74. $dtp->LoadSource($this->info);
  75. $formstring = '';
  76. $formfields = '';
  77. $func = $type == 'post' ? 'GetFormItem' : 'GetFormItemValue';
  78. if (is_array($dtp->CTags)) {
  79. foreach ($dtp->CTags as $tagid => $tag) {
  80. if ($tag->GetAtt('autofield')) {
  81. if ($type == 'post') {
  82. $formstring .= $func($tag, $admintype);
  83. } else {
  84. $formstring .= $func($tag, dede_htmlspecialchars($value[$tag->GetName()], ENT_QUOTES), $admintype);
  85. }
  86. $formfields .= $formfields == '' ? $tag->GetName() . ',' . $tag->GetAtt('type') : ';' . $tag->GetName() . ',' . $tag->GetAtt('type');
  87. }
  88. }
  89. }
  90. $formstring .= "<input type=\"hidden\" name=\"dede_fields\" value=\"" . $formfields . "\" />\n";
  91. $formstring .= "<input type=\"hidden\" name=\"dede_fieldshash\" value=\"" . md5($formfields . $cfg_cookie_encode) . "\" />";
  92. return $formstring;
  93. }
  94. /**
  95. * 获取字段列表
  96. *
  97. * @access public
  98. * @return string
  99. */
  100. function getFieldList()
  101. {
  102. $dtp = new DedeTagParse();
  103. $dtp->SetNameSpace("field", "<", ">");
  104. $dtp->LoadSource($this->info);
  105. $fields = array();
  106. if (is_array($dtp->CTags)) {
  107. foreach ($dtp->CTags as $tagid => $tag) {
  108. $fields[$tag->GetName()] = array($tag->GetAtt('itemname'), $tag->GetAtt('type'));
  109. }
  110. }
  111. return $fields;
  112. }
  113. }//End Class