cache_threadsorts.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: cache_threadsorts.php 26205 2011-12-05 10:09:32Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function build_cache_threadsorts() {
  12. $sortlist = $templatedata = $stemplatedata = $ptemplatedata = $btemplatedata = $template = array();
  13. $query = C::t('forum_threadtype')->fetch_all_for_cache();
  14. foreach($query as $data) {
  15. $data['rules'] = dunserialize($data['rules']);
  16. $sortid = $data['sortid'];
  17. $optionid = $data['optionid'];
  18. $sortlist[$sortid][$optionid] = array(
  19. 'title' => dhtmlspecialchars($data['title']),
  20. 'type' => dhtmlspecialchars($data['type']),
  21. 'unit' => dhtmlspecialchars($data['unit']),
  22. 'identifier' => dhtmlspecialchars($data['identifier']),
  23. 'description' => dhtmlspecialchars($data['description']),
  24. 'permprompt' => $data['permprompt'],
  25. 'required' => intval($data['required']),
  26. 'unchangeable' => intval($data['unchangeable']),
  27. 'search' => intval($data['search']),
  28. 'subjectshow' => intval($data['subjectshow']),
  29. 'expiration' => intval($data['expiration']),
  30. 'protect' => dunserialize($data['protect']),
  31. );
  32. if(in_array($data['type'], array('select', 'checkbox', 'radio'))) {
  33. if($data['rules']['choices']) {
  34. $choices = array();
  35. foreach(explode("\n", $data['rules']['choices']) as $item) {
  36. list($index, $choice) = explode('=', $item);
  37. $choices[trim($index)] = trim($choice);
  38. }
  39. $sortlist[$sortid][$optionid]['choices'] = $choices;
  40. } else {
  41. $sortlist[$sortid][$optionid]['choices'] = array();
  42. }
  43. if($data['type'] == 'select') {
  44. $sortlist[$sortid][$optionid]['inputsize'] = $data['rules']['inputsize'] ? intval($data['rules']['inputsize']) : 108;
  45. }
  46. } elseif(in_array($data['type'], array('text', 'textarea', 'calendar'))) {
  47. $sortlist[$sortid][$optionid]['maxlength'] = intval($data['rules']['maxlength']);
  48. if($data['type'] == 'textarea') {
  49. $sortlist[$sortid][$optionid]['rowsize'] = $data['rules']['rowsize'] ? intval($data['rules']['rowsize']) : 5;
  50. $sortlist[$sortid][$optionid]['colsize'] = $data['rules']['colsize'] ? intval($data['rules']['colsize']) : 50;
  51. } else {
  52. $sortlist[$sortid][$optionid]['inputsize'] = $data['rules']['inputsize'] ? intval($data['rules']['inputsize']) : '';
  53. }
  54. if(in_array($data['type'], array('text', 'textarea'))) {
  55. $sortlist[$sortid][$optionid]['defaultvalue'] = $data['rules']['defaultvalue'];
  56. }
  57. if($data['type'] == 'text') {
  58. $sortlist[$sortid][$optionid]['profile'] = $data['rules']['profile'];
  59. }
  60. } elseif($data['type'] == 'image') {
  61. $sortlist[$sortid][$optionid]['maxwidth'] = intval($data['rules']['maxwidth']);
  62. $sortlist[$sortid][$optionid]['maxheight'] = intval($data['rules']['maxheight']);
  63. $sortlist[$sortid][$optionid]['inputsize'] = $data['rules']['inputsize'] ? intval($data['rules']['inputsize']) : '';
  64. } elseif(in_array($data['type'], array('number', 'range'))) {
  65. $sortlist[$sortid][$optionid]['inputsize'] = $data['rules']['inputsize'] ? intval($data['rules']['inputsize']) : '';
  66. $sortlist[$sortid][$optionid]['maxnum'] = intval($data['rules']['maxnum']);
  67. $sortlist[$sortid][$optionid]['minnum'] = intval($data['rules']['minnum']);
  68. if($data['rules']['searchtxt']) {
  69. $sortlist[$sortid][$optionid]['searchtxt'] = explode(',', $data['rules']['searchtxt']);
  70. }
  71. if($data['type'] == 'number') {
  72. $sortlist[$sortid][$optionid]['defaultvalue'] = $data['rules']['defaultvalue'];
  73. }
  74. }
  75. }
  76. $query = C::t('forum_threadtype')->range();
  77. foreach($query as $data) {
  78. $templatedata[$data['typeid']] = addcslashes($data['template'], '",\\');
  79. $stemplatedata[$data['typeid']] = addcslashes($data['stemplate'], '",\\');
  80. $ptemplatedata[$data['typeid']] = addcslashes($data['ptemplate'], '",\\');
  81. $btemplatedata[$data['typeid']] = addcslashes($data['btemplate'], '",\\');
  82. }
  83. $data['sortoption'] = $data['template'] = array();
  84. foreach($sortlist as $sortid => $option) {
  85. $template['viewthread'] = $templatedata[$sortid];
  86. $template['subject'] = $stemplatedata[$sortid];
  87. $template['post'] = $ptemplatedata[$sortid];
  88. $template['block'] = $btemplatedata[$sortid];
  89. savecache('threadsort_option_'.$sortid, $option);
  90. savecache('threadsort_template_'.$sortid, $template);
  91. }
  92. }
  93. ?>