one($content_id); if ($content) { if (!$content['pic']) { # 如果封面图不存在,就自动生成 $pic = Dever::param('pic', $data); if ($pic) { $update['pic'] = Dever::load('upload/view')->get($pic, 'c', 1); } else { $text = Dever::param('text', $data); if ($text && isset($text[0]['pic']) && $text[0]['pic']) { $update['pic'] = Dever::load('upload/view')->get($text[0]['pic'], 'c', 1); } } } $update['where_id'] = $content_id; Dever::db('collection/content')->update($update); } } } # 获取某一个合集的内容列表 public function getList($user, $info_id, $page_id, $show = true, $index = 0, $page = array()) { $where['info_id'] = $info_id; $where['page_id'] = $page_id; $data = Dever::db('collection/content')->getAllPage($where); $result = array(); if ($data) { $i = 0; # 获取章节信息 //$page = Dever::db('collection/page')->one($page_id); if ($page && $page['desc']) { $parent_page = Dever::db('collection/page')->one($page['page_id']); $page['parent_name'] = $parent_page['name']; $page['name'] = $page['name']; $info = Dever::db('collection/info')->one($info_id); if ($info && $info['uid'] > 0) { $page['author_name'] = $info['author_name'] . ':'; $userinfo = Dever::load('user/lib/info')->get($info['uid'], $info_id); $page['username'] = $userinfo['username']; $page['copyright'] = '所有内容为网友上传,不代表合小记观点'; } else { $page['author_name'] = ''; $page['username'] = '官方'; $page['copyright'] = '所有内容仅供内部专用,禁止在互联网传播'; } $result[$i] = $page; $result[$i]['id'] = $info_id . '_' . $page['id']; $result[$i]['data'] = -1; $result[$i]['type'] = -1; $result[$i]['times'] = $result[$i]['times_parent'] = ''; if ($page['times_id_parent'] && $page['times_id']) { $times = Dever::db('collection/times')->one($page['times_id']); $result[$i]['times'] = $times['name']; $times = Dever::db('collection/times')->one($page['times_id_parent']); $result[$i]['times_parent'] = $times['name']; } $i = 1; } foreach ($data as $k => $v) { if (!$show) { if ($i != $index) { $result[$i] = array(); } else { $data[$k] = $this->getOne($v, $user); if ($data[$k]['data']) { $result[$i] = $data[$k]; } } $i++; } else { $data[$k] = $this->getOne($v, $user); if ($data[$k]['data']) { $result[$i] = $data[$k]; $i++; } } } if ($page && $page['desc_end']) { $result[$i] = $result[0]; $result[$i]['desc'] = $page['desc_end']; if ($page['pic_end']) { $result[$i]['pic'] = $page['pic_end']; } } } return $result; } public function getOne($data, $user = array()) { $type = Dever::db('collection/cate')->config['gettype']; $table = $type[$data['type']]['table']; if (!$table) { return $data; } $method = 'one'; if (strstr($table, '-')) { $temp = explode('-', $table); $table = $temp[0]; $method = $temp[1]; } $data['data'] = Dever::db($table)->$method(array('content_id' => $data['id'], 'info_id' => $data['info_id'])); if ($data['data']) { if (isset($data['data']['id'])) { $data['data'] = $this->getData($data['data'], $user); } else { foreach ($data['data'] as $k => $v) { $data['data'][$k] = $this->getData($v, $user); } } } return $data; } public function getData($data, $user = array()) { $data['num_view'] = 1; $data['date'] = ''; if (isset($data['cdate'])) { $data['date'] = date('Y-m-d H:i:s', $data['cdate']); } if (isset($data['text']) && $data['text']) { $data['text'] = Dever::array_decode($data['text']); foreach ($data['text'] as $k => $v) { if (isset($v['name']) && $v['name']) { $data['text'][$k]['name_array'] = explode("\r\n", $v['name']); } else { unset($data['text'][$k]); continue; } if (isset($v['bgcolor_type']) && $v['bgcolor_type'][0] == 2) { $data['text'][$k]['bgcolor'] = ''; } if (isset($v['content']) && $v['content']) { $data['text'][$k]['content_array'] = $this->getContent($v); } } } else { $data['text'] = array(); } if (isset($data['author_id']) && $data['author_id'] > 0) { $data['author'] = Dever::db('store/author')->one($data['author_id']); } # 歌词 if (isset($data['lrc']) && $data['lrc']) { $data['lrc'] = strip_tags($data['lrc']); $data['lrc'] = explode("\r\n", $data['lrc']); } if (isset($data['content']) && $data['content']) { $data = $this->getContent($data); } if (isset($data['goods_id']) && $data['goods_id'] > 0) { $data['goods'] = Dever::load('goods/lib/info')->getInfo($data['goods_id'], true, 'view_reorder', $user); $data['goods'] = $this->getContent($data['goods']); } unset($data['info_id']); unset($data['content_id']); unset($data['status']); unset($data['state']); unset($data['cdate']); unset($data['reorder']); unset($data['udate']); return $data; } public function getContent($data, $uid = false) { //embed $data['content_array'] = $data['content_pic'] = array(); $data['content'] = Dever::filter($data['content']); $content = $data['content']; $replace = array(); # 过滤宽度 if (strstr($data['content'], 'width:')) { $content = preg_replace('/width:(.*?)px/', 'width:100%', $content); } # 小程序 if (strstr($data['content'], 'data-applet')) { preg_match_all('//', $content, $matches); if (isset($matches[2])) { foreach ($matches[2] as $k => $v) { $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content); $temp = explode('||', $v); $pic = $temp[0]; $appid = $temp[1]; $path = $temp[2]; if ($appid) { $appinfo = Dever::db('content/applet')->one(array('appid' => $appid)); } else { $appinfo['name'] = ''; $appinfo['link'] = ''; } if (isset($temp[3]) && $temp[3]) { $appinfo['link'] = $temp[3]; } $replace[] = array('type' => 'applet', 'pic_cover' => $pic, 'appid' => $appid, 'path' => $path, 'name' => $appinfo['name'], 'link' => $appinfo['link']); } } } # 图片 if (strstr($data['content'], '/', $content, $matches); if (isset($matches[2])) { foreach ($matches[2] as $k => $v) { $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content); $pic = $v; $replace[] = array('type' => 'pic', 'content' => $pic); $data['content_pic'][] = $pic; } } } # 音视频 if (strstr($data['content'], 'data-file')) { preg_match_all('//', $content, $matches); if (!isset($matches[1][0])) { preg_match_all('//', $content, $matches); $temp = array(); if (isset($matches[2][0])) { $temp = $matches; $matches[1] = $temp[2]; unset($temp); } } if (isset($matches[1])) { foreach ($matches[1] as $k => $v) { if (isset($matches[3][$k])) { $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content); $file = $matches[3][$k]; $temp = explode('||', $file); $file = $temp[0]; if (isset($temp[1])) { $name = $temp[1]; } else { $name = ''; } $cover = $v; if (strstr($v, '.mp4') || strstr($v, '.mov') || strstr($v, '.m3u8')) { $replace[] = array('type' => 'video', 'content' => $file, 'cover' => $cover, 'name' => $name); } else { $replace[] = array('type' => 'audio', 'content' => $file, 'cover' => $cover, 'name' => $name); } } } } } # 视频+直播 if (strstr($data['content'], 'data-id')) { preg_match_all('//', $content, $matches); if (!isset($matches[2][0])) { preg_match_all('//', $content, $matches); $temp = array(); if (isset($matches[2][0]) && isset($matches[3][0])) { $temp = $matches; $matches[2] = $temp[3]; $matches[3] = $temp[2]; unset($temp); } } if (isset($matches[2][0]) && isset($matches[3][0])) { foreach ($matches[2] as $k => $v) { $content = str_replace($matches[0][$k], '{replace}'.count($replace).'{replace}', $content); if ($matches[3][$k] == 'video/lib/core.vod') { $method = 'video/lib/vod'; $type = 'video'; } else { $type = 'live'; $method = 'video/lib/live'; } $info = Dever::load($method)->get($v); if (isset($info['content'])) { unset($info['content']); } if ($type == 3) { # 查看是否有预约 if ($uid > 0) { $info['user_act']['note'] = Dever::load('user/lib/note')->get($uid, $v, $type); } else { $info['user_act']['note'] = 2; } } $replace[] = array('id' => $v, 'type' => $type, 'content' => $info); } } } //$data['content'] = preg_replace('/
([\s\S]*?)<\/div>/i', '', $data['content']); $content = explode('{replace}', $content); $data['content_array'] = array(); //print_r($content);die; foreach ($content as $k => $v) { $v = trim($v); if (is_numeric($v) && $v >= 0 && isset($replace[$v])) { $data['content_array'][] = $replace[$v]; } elseif ($v) { $data['content_array'][] = array ( 'type' => 'html', 'content' => $v, ); } } if (!$data['content_array']) { $data['content_array'][] = array ( 'type' => 'html', 'content' => $data['content'], ); } unset($data['content']); //print_r($data['content_array']);die; return $data; } }