国内流行的内容管理系统(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.

diyform.class.php 4.1KB

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