/caches/caches_model/caches_data/member_output.class.php

https://github.com/hxzyzz/ddc · PHP · 176 lines · 169 code · 6 blank · 1 comment · 32 complexity · ef37aff00260aa0f72c37ee50cb5e786 MD5 · raw file

  1. <?php
  2. class member_output {
  3. var $fields;
  4. var $data;
  5. function __construct($modelid,$catid = 0,$categorys = array()) {
  6. $this->modelid = $modelid;
  7. $this->catid = $catid;
  8. $this->categorys = $categorys;
  9. $this->fields = getcache('model_field_'.$modelid,'model');
  10. }
  11. function get($data) {
  12. $this->data = $data;
  13. $this->id = $data['id'];
  14. $info = array();
  15. foreach($this->fields as $field=>$v) {
  16. if(!isset($data[$field])) continue;
  17. $func = $v['formtype'];
  18. $value = $data[$field];
  19. $result = method_exists($this, $func) ? $this->$func($field, $data[$field]) : $data[$field];
  20. if($result !== false) $info[$field] = $result;
  21. }
  22. return $info;
  23. }
  24. function editor($field, $value) {
  25. $setting = string2array($this->fields[$field]['setting']);
  26. if($setting['enablekeylink']) {
  27. $data = $this->_keylinks($value, $setting['replacenum'],$setting['link_mode']);
  28. }
  29. return $data;
  30. }
  31. function _base64_encode($t,$str) {
  32. return $t."\"".base64_encode($str)."\"";
  33. }
  34. function _base64_decode($t,$str) {
  35. return $t."\"".base64_decode($str)."\"";
  36. }
  37. function _keylinks($txt, $replacenum = '',$link_mode = 1) {
  38. $txt = addslashes($txt);
  39. $search = "/(alt\s*=\s*|title\s*=\s*)[\"|\'](.+?)[\"|\']/ise";
  40. $replace = "$this->_base64_encode('\\1','\\2')";
  41. $replace1 = "$this->_base64_decode('\\1','\\2')";
  42. $txt = preg_replace($search, $replace, $txt);
  43. $keywords = $this->data['keywords'];
  44. if($keywords) $keywords = strpos(',',$keywords) === false ? explode(' ',$keywords) : explode(',',$keywords);
  45. if($link_mode && !empty($keywords)) {
  46. foreach($keywords as $keyword) {
  47. $linkdatas[] = $keyword;
  48. }
  49. } else {
  50. //TODO
  51. $linkdatas = array(
  52. 0 => array(0=>'ÍøÕ¾',1=>'http://www.phpip.com'),
  53. 1 => array(0=>'°Ù¶È',1=>'http://www.baidu.com'),
  54. );
  55. }
  56. if($linkdatas) {
  57. $word = $replacement = array();
  58. foreach($linkdatas as $v) {
  59. if($link_mode && $keywords) {
  60. $word1[] = '/'.preg_quote($v, '/').'/';
  61. $word2[] = $v;
  62. $replacement[] = '<a href="javascript:;" onclick="show_ajax(this)" class="keylink">'.$v.'</a>';
  63. } else {
  64. $word1[] = '/'.preg_quote($v[0], '/').'/';
  65. $word2[] = $v[0];
  66. $replacement[] = '<a href="'.$v[1].'" target="_blank" class="keylink">'.$v[0].'</a>';
  67. }
  68. }
  69. if($replacenum != '') {
  70. $txt = preg_replace($word1, $replacement, $txt, $replacenum);
  71. } else {
  72. $txt = str_replace($word2, $replacement, $txt);
  73. }
  74. }
  75. $txt = preg_replace($search, $replace1, $txt);
  76. $txt = stripslashes($txt);
  77. return $txt;
  78. }
  79. function box($field, $value) {
  80. extract(string2array($this->fields[$field]['setting']));
  81. if($outputtype) {
  82. return $value;
  83. } else {
  84. $options = explode("\n",$this->fields[$field]['options']);
  85. foreach($options as $_k) {
  86. $v = explode("|",$_k);
  87. $k = trim($v[1]);
  88. $option[$k] = $v[0];
  89. }
  90. $string = '';
  91. switch($this->fields[$field]['boxtype']) {
  92. case 'radio':
  93. $string = $option[$value];
  94. break;
  95. case 'checkbox':
  96. $value_arr = explode(',',$value);
  97. foreach($value_arr as $_v) {
  98. if($_v) $string .= $option[$_v].' ¡¢';
  99. }
  100. break;
  101. case 'select':
  102. $string = $option[$value];
  103. break;
  104. case 'multiple':
  105. $value_arr = explode(',',$value);
  106. foreach($value_arr as $_v) {
  107. if($_v) $string .= $option[$_v].' ¡¢';
  108. }
  109. break;
  110. }
  111. return $string;
  112. }
  113. }
  114. function images($field, $value) {
  115. return string2array($value);
  116. }
  117. function datetime($field, $value) {
  118. $setting = string2array($this->fields[$field]['setting']);
  119. extract($setting);
  120. if($fieldtype=='date') {
  121. $format_txt = 'Y-m-d';
  122. } elseif($fieldtype=='datetime') {
  123. $format_txt = 'Y-m-d H:i:s';
  124. } else {
  125. $format_txt = $format;
  126. }
  127. if(strlen($format_txt)<6) {
  128. $isdatetime = 0;
  129. } else {
  130. $isdatetime = 1;
  131. }
  132. if(!$value) $value = SYS_TIME;
  133. $value = date($format_txt,$value);
  134. return $value;
  135. }
  136. function linkage($field, $value) {
  137. $setting = string2array($this->fields[$field]['setting']);
  138. $datas = getcache($setting['linkageid'],'linkage');
  139. $infos = $datas['data'];
  140. if($setting['showtype']==1) {
  141. $result = $this->_get_parent($value, $setting['linkageid'], $setting['space']);
  142. } elseif($setting['showtype']==2) {
  143. $result = $value;
  144. } else {
  145. $result = $infos[$value]['name'];
  146. }
  147. return $result;
  148. }
  149. function _get_parent($linkageid, $keyid, $space = '>', $result = array(), $infos = array()) {
  150. if($space=='' || !isset($space))$space = '>';
  151. if(!$infos) {
  152. $datas = getcache($keyid,'linkage');
  153. $infos = $datas['data'];
  154. }
  155. if(array_key_exists($linkageid,$infos)) {
  156. $result[]=$infos[$linkageid]['name'];
  157. return $this->_get_parent($infos[$linkageid]['parentid'], $keyid, $space, $result, $infos);
  158. } else {
  159. if(count($result)>0) {
  160. krsort($result);
  161. $result = implode($space,$result);
  162. return $result;
  163. }
  164. else {
  165. return $result;
  166. }
  167. }
  168. }
  169. }
  170. ?>