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

127 lines
4.2KB

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