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

108 lines
3.9KB

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