content_update.class.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. class content_update {
  3. var $modelid;
  4. var $fields;
  5. var $data;
  6. function __construct($modelid,$id) {
  7. $this->modelid = $modelid;
  8. $this->fields = getcache('model_field_'.$modelid,'model');
  9. $this->id = $id;
  10. }
  11. function update($data) {
  12. $info = array();
  13. $this->data = $data;
  14. foreach($data as $field=>$value) {
  15. if(!isset($this->fields[$field])) continue;
  16. $func = $this->fields[$field]['formtype'];
  17. $info[$field] = method_exists($this, $func) ? $this->$func($field, $value) : $value;
  18. }
  19. }
  20. function editor($field, $value) {
  21. $attachment_db = pc_base::load_model('attachment_model');
  22. $attachment_db->api_update($GLOBALS['downloadfiles'],'c-'.$this->data['catid'].'-'.$this->id,1);
  23. return $value;
  24. } function posid($field, $value) {
  25. if(!empty($value) && is_array($value)) {
  26. if($_GET['a']=='add') {
  27. $position_data_db = pc_base::load_model('position_data_model');
  28. $textcontent = array();
  29. foreach($value as $r) {
  30. if($r!='-1') {
  31. if(empty($textcontent)) {
  32. foreach($this->fields AS $_key=>$_value) {
  33. if($_value['isposition']) {
  34. $textcontent[$_key] = $this->data[$_key];
  35. }
  36. }
  37. $textcontent = array2string($textcontent);
  38. }
  39. $thumb = $this->data['thumb'] ? 1 : 0;
  40. $position_data_db->insert(array('id'=>$this->id,'catid'=>$this->data['catid'],'posid'=>$r,'thumb'=>$thumb,'module'=>'content','modelid'=>$this->modelid,'data'=>$textcontent,'listorder'=>$this->id,'siteid'=>get_siteid()));
  41. }
  42. }
  43. } else {
  44. $posids = array();
  45. $catid = $this->data['catid'];
  46. $push_api = pc_base::load_app_class('push_api','admin');
  47. foreach($value as $r) {
  48. if($r!='-1') $posids[] = $r;
  49. }
  50. $textcontent = array();
  51. foreach($this->fields AS $_key=>$_value) {
  52. if($_value['isposition']) {
  53. $textcontent[$_key] = $this->data[$_key];
  54. }
  55. }
  56. //颜色选择为隐藏域 在这里进行取值
  57. $textcontent['style'] = $_POST['style_color'] ? strip_tags($_POST['style_color']) : '';
  58. $textcontent['inputtime'] = strtotime($textcontent['inputtime']);
  59. if($_POST['style_font_weight']) $textcontent['style'] = $textcontent['style'].';'.strip_tags($_POST['style_font_weight']);
  60. $push_api->position_update($this->id, $this->modelid, $catid, $posids, $textcontent,0);
  61. }
  62. }
  63. }
  64. function keyword ($field, $value) {
  65. //获取post过来的关键字,关键字用空格或者‘,’分割的
  66. $data = array();
  67. $data = preg_split("/[ ,]+/", $value);
  68. //加载关键字的数据模型
  69. $keyword_db = pc_base::load_model('keyword_model');
  70. $keyword_data_db = pc_base::load_model('keyword_data_model');
  71. pc_base::load_sys_func('iconv');
  72. if (is_array($data) && !empty($data)) {
  73. $siteid = get_siteid();
  74. foreach ($data as $v) {
  75. $v = defined('IN_ADMIN') ? $v : safe_replace(addslashes($v));
  76. $v = str_replace(array('//','#','.'),' ',$v);
  77. if (!$r = $keyword_db->get_one(array('keyword'=>$v, 'siteid'=>$siteid))) {
  78. $letters = gbk_to_pinyin($v);
  79. $letter = strtolower(implode('', $letters));
  80. $tagid = $keyword_db->insert(array('keyword'=>$v, 'siteid'=>$siteid, 'pinyin'=>$letter, 'videonum'=>1), true);
  81. } else {
  82. $keyword_db->update(array('videonum'=>'+=1'), array('id'=>$r['id']));
  83. $tagid = $r['id'];
  84. }
  85. $contentid = $this->id.'-'.$this->modelid;
  86. if (!$keyword_data_db->get_one(array('tagid'=>$tagid, 'siteid'=>$siteid, 'contentid'=>$contentid))) {
  87. $keyword_data_db->insert(array('tagid'=>$tagid, 'siteid'=>$siteid, 'contentid'=>$contentid));
  88. }
  89. unset($contentid, $tagid, $letters);
  90. }
  91. }
  92. return $value;
  93. }
  94. function video($field, $value) {
  95. if ($value) {
  96. $value = $GLOBALS[$field];
  97. } else {
  98. return '';
  99. }
  100. $video_content_db = pc_base::load_model('video_content_model');
  101. //先获取目前contentid下面的videoid
  102. $result = $video_content_db->select(array('contentid'=>$this->id, 'modelid'=>$this->modelid), 'videoid');
  103. if (is_array($result)) {
  104. $video_arr = array();
  105. foreach ($result as $r) {
  106. $video_arr[] = $r['videoid'];
  107. }
  108. }
  109. if(!empty($value) && is_array($value)) {
  110. foreach ($value as $v) {
  111. if (!empty($video_arr) && !in_array($v['videoid'], $video_arr)) {
  112. $video_content_db->insert(array('contentid'=>$this->id, 'modelid'=>$this->modelid, 'videoid'=>$v['videoid'], 'listorder'=>$v['listorder']));
  113. $s_key = array_search($v['videoid'], $video_arr);
  114. unset($video_arr[$s_key]);
  115. } elseif (empty($video_arr)) {
  116. $video_content_db->insert(array('contentid'=>$this->id, 'modelid'=>$this->modelid, 'videoid'=>$v['videoid'], 'listorder' => $v['listorder']));
  117. } elseif (in_array($v['videoid'], $video_arr)) {
  118. $video_content_db->update(array('listorder'=>$v['listorder']), array('contentid'=>$this->id, 'modelid'=>$this->modelid, 'videoid'=>$v['videoid']));
  119. $s_key = array_search($v['videoid'], $video_arr);
  120. unset($video_arr[$s_key]);
  121. }
  122. }
  123. //删除需要删除的videoid
  124. if ($video_arr && !empty($video_arr)) {
  125. foreach ($video_arr as $dvid) {
  126. $video_content_db->delete(array('contentid'=>$this->id, 'modelid'=>$this->modelid, 'videoid'=>$dvid));
  127. }
  128. }
  129. } elseif (!empty($video_arr) && is_array($video_arr)) {
  130. foreach ($video_arr as $dvid) {
  131. $video_content_db->delete(array('contentid'=>$this->id, 'modelid'=>$this->modelid, 'videoid'=>$dvid));
  132. }
  133. }
  134. }
  135. }
  136. ?>