创建主题内容数据,并关联相关数据
function thread_create_handle($arr)
{
global $longip, $gid, $uid, $config;
if (empty($arr)) return FALSE;
// 管理员和后台无需审核
$publishverify = 1 == $gid || (!empty($arr['admin']) && group_access($gid, 'managecreatethread')) || !group_access($gid, 'publishverify');
// hook model_thread_create_handle_start.php
// 防止扩展出错
$conf = array_value($arr, 'conf');
$time = array_value($arr, 'time', time());
$longip = array_value($arr, 'longip');
$gid = array_value($arr, 'gid', 0);
$uid = array_value($arr, 'uid', $uid);
$forumlist = forum_list_cache();
$config = setting_get('conf');
$fid = array_value($arr, 'fid', 0);
$forum = array_value($forumlist, $fid);
$subject = array_value($arr, 'subject');
$type = array_value($arr, 'type', 0);
$closed = array_value($arr, 'closed', 0);
$keyword = array_value($arr, 'keyword');
$brief = array_value($arr, 'brief');
$description = array_value($arr, 'description');
$flags = array_value($arr, 'flags');
$message = array_value($arr, 'message');
$thumbnail = array_value($arr, 'thumbnail', 0); // 内容主图
$save_image = array_value($arr, 'save_image', 0); // 图片本地化
$doctype = array_value($arr, 'doctype', 0);
$status = array_value($arr, 'status', 0);
$thread_default = array_value($arr, 'thread_default', 1); // 默认入库方便扩展
// hook model__thread_create_before.php
// 创建主题
$thread = array('fid' => $fid, 'subject' => $subject, 'type' => $type, 'brief' => $brief, 'uid' => $uid, 'create_date' => $time, 'closed' => $closed, 'keyword' => $keyword, 'description' => $description, 'last_date' => $time, 'userip' => $longip, 'flags' => $flags);
$thread['status'] = TRUE === $publishverify ? 0 : 1;
// hook model__thread_create_thread_after.php
$upload_thumbnail = well_attach_assoc_type('thumbnail'); // 缩略图主图
!empty($upload_thumbnail) and $thread['icon'] = $time;
// hook model_thread_create_handle_center.php
// 主题入库
$tid = well_thread__create($thread);
if (FALSE === $tid) return FALSE;
unset($thread);
// hook model_thread_create_handle_after.php
// 关联主图 assoc:thumbnail
if (!empty($upload_thumbnail)) {
// 上传了主图
// hook model_thread_create_thumbnail_before.php
$arr = array('tid' => $tid, 'uid' => $uid);
// hook model_thread_create_thumbnail_after.php
well_attach_assoc_thumbnail($arr);
unset($arr);
$thumbnail = 0;
}
// hook model_thread_create_save_image_before.php
!forum_access_user($fid, $gid, 'allowattach') and $save_image = 0;
// hook model_thread_create_attach_before.php
$assoc = array('uid' => $uid, 'gid' => $gid, 'tid' => $tid, 'fid' => $fid, 'time' => $time, 'conf' => $conf, 'message' => $message, 'thumbnail' => $thumbnail, 'save_image' => $save_image, 'sess_file' => 1);
// hook model_thread_create_assoc_before.php
$result = well_attach_assoc_handle($assoc);
unset($assoc);
$message = $result['message'];
$icon = $result['icon'];
$images = $result['images'];
$files = $result['files'];
// hook model_thread_create_data_handle_before.php
// 主题数据入库
$data = array('tid' => $tid, 'gid' => $gid, 'message' => $message, 'doctype' => $doctype);
// hook model_thread_create_data_handle_after.php
$tid = data_create($data);
if (FALSE === $tid) return FALSE;
unset($data);
// hook model_thread_create_verify_before.php
$user_update = array();
// hook model_thread_create_verify_center.php
if (1 == $thread_default) {
// 我的主题 审核成功写入该表 website_thread_tid表
if (TRUE === $publishverify) {
// hook model__thread_create_forum_update_before.php
$forum_update = array('threads+' => 1, 'todaythreads+' => 1);
// hook model__thread_create_forum_update_center.php
$fid and forum_update($fid, $forum_update);
unset($forum_update);
// hook model__thread_create_tid_start.php
// 对模型区分,如需要全站扁平,在首页出现,需写入thread_tid,其他模型原有代码不变,可单独写入各自模型小表
switch (array_value($forum, 'model')) {
// hook model__thread_create_case_start.php
case '0':
$thread_tid_create = array('tid' => $tid, 'fid' => $fid, 'uid' => $uid);
// hook model__thread_create_tid_before.php
thread_tid_create($thread_tid_create);
// hook model__thread_create_tid_center.php
$user_update['articles+'] = 1;
// hook model__thread_create_tid_middle.php
runtime_set('articles+', 1);
runtime_set('todayarticles+', 1);
// hook model__thread_create_tid_after.php
break;
// hook model__thread_create_case_end.php
}
// hook model__thread_create_tid_end.php
// 门户模式删除首页所有缓存
if (1 == array_value($config, 'model')) {
cache_delete('portal_index_thread');
$fid and cache_delete('portal_channel_thread_' . $fid);
}
// hook model__thread_create_portal_after.php
} else {
// 待审核 / Waiting for verification
// hook model__thread_create_tid_verify_start.php
switch (array_value($forum, 'model')) {
// hook model__thread_create_verify_case_start.php
/*case 0:
break;*/
// hook model__thread_create_verify_case_end.php
}
// hook model__thread_create_tid_verify_end.php
}
}
// hook model_thread_create_verify_after.php
// 更新统计数据 返回到路由处理
//!empty($user_update) and user_update($uid, $user_update);
$return = array('tid' => $tid, 'icon' => $icon, 'images' => $images, 'files' => $files, 'user_update' => $user_update);
// hook model_thread_create_handle_end.php
return $return;
}