function getDeleteFileConfirmFormData($file_id) { global $xoopsModuleConfig; $file_handler =& XsnsFileHandler::getInstance(); $file =& $file_handler->get($file_id); if(!is_object($file)){ return false; } $file_info =& $file->getInfo(); $filename = $xoopsModuleConfig['file_upload_path']. '/'. $file_info['filename']; if(!file_exists($filename)){ return false; } $ext_to_mime = include(XOOPS_ROOT_PATH.'/class/mimetypes.inc.php'); $path_parts = @pathinfo($filename); $file_stat = @stat($filename); $form = array( 'title' => _MD_XSNS_TITLE_FILE, 'desc' => _MD_XSNS_FILE_DEL_FILE_DESC, 'file_name_desc' => _MD_XSNS_FILE_NAME, 'name' => $file_info['caption'], 'size' => filesize($filename), 'type' => @$ext_to_mime[$path_parts['extension']], 'time' => date('Y-m-d H:i:s', $file_stat['mtime']), ); return $form; }
function dispatch() { if(!$this->validateToken('FILE_DELETE')){ redirect_header(XOOPS_URL, 2, _NOPERM); } $image_id = $this->getIntRequest('image_id'); $file_id = $this->getIntRequest('file_id'); if(($image_id > 0 && $file_id > 0) || !$this->checkAuthority($image_id, $file_id)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $url = XSNS_URL_COMMU; if($image_id > 0){ $image_handler =& XsnsImageHandler::getInstance(); $image =& $image_handler->get($image_id); if(is_object($image) && $image_handler->delete($image)){ $msg = _MD_XSNS_FILE_DEL_IMAGE_OK; $url = $this->getRedirectURL($image->getVar('target'), $image->getVar('target_id')); } else{ $msg = _MD_XSNS_FILE_DEL_IMAGE_NG; } } elseif($file_id > 0){ $file_handler =& XsnsFileHandler::getInstance(); $file =& $file_handler->get($file_id); if(is_object($file) && $file_handler->delete($file)){ $msg = _MD_XSNS_FILE_DEL_FILE_OK; $url = $this->getRedirectURL($file->getVar('target'), $file->getVar('target_id')); } else{ $msg = _MD_XSNS_FILE_DEL_FILE_NG; } } else{ redirect_header(XOOPS_URL, 2, _NOPERM); } if(empty($url)){ redirect_header(XOOPS_URL, 2, _NOPERM); } redirect_header($url, 2, $msg); }
function XsnsTopicComment() { // $key, $data_type, $default, $required, $size $this->initVar('c_commu_topic_comment_id', XOBJ_DTYPE_INT); $this->initVar('c_commu_topic_id', XOBJ_DTYPE_INT); $this->initVar('c_commu_id', XOBJ_DTYPE_INT); $this->initVar('uid', XOBJ_DTYPE_INT); $this->initVar('body', XOBJ_DTYPE_TXTAREA); $this->initVar('r_datetime', XOBJ_DTYPE_DATETIME); $this->initVar('r_date', XOBJ_DTYPE_DATE); $this->initVar('number', XOBJ_DTYPE_INT); $this->handler = array( 'image' => XsnsImageHandler::getInstance(), 'file' => XsnsFileHandler::getInstance(), 'comment' => XsnsTopicCommentHandler::getInstance(), ); }
function dispatch() { if(!$this->validateToken('FILE_DELETE')){ redirect_header(XSNS_URL_ADMIN, 2, _NOPERM); } $del_id = isset($_POST['delete']) ? $_POST['delete'] : NULL; if(is_null($del_id) || !is_array($del_id)){ redirect_header(XSNS_URL_ADMIN.'?'.XSNS_ACTION_ARG.'=file', 2, _AM_XSNS_FILE_SELECT_NG); } $file_handler =& XsnsFileHandler::getInstance(); foreach($del_id as $id){ $file =& $file_handler->get($id); $file_handler->delete($file); } redirect_header(XSNS_URL_ADMIN.'?'.XSNS_ACTION_ARG.'=file', 2, _AM_XSNS_FILE_DELETE_OK); }
function dispatch() { if($this->isGuest()){ redirect_header(XOOPS_URL, 2, _NOPERM); } $cid = $this->getIntRequest('cid', XSNS_REQUEST_GET); if(!isset($cid)){ redirect_header(XOOPS_URL, 2, _NOPERM); } // コミュニティの取得 $commu_handler =& XsnsCommunityHandler::getInstance(); $community =& $commu_handler->get($cid); if(!is_object($community) || !$community->checkAuthority()){ redirect_header(XOOPS_URL, 2, _NOPERM); } // 画像・ファイルのキャッシュを削除 $image_handler =& XsnsImageHandler::getInstance(); $image_handler->deleteImageTemp(); $file_handler =& XsnsFileHandler::getInstance(); $file_handler->deleteFileTemp(); $sess_handler =& XsnsSessionHandler::getInstance(); $topic_temp = $sess_handler->getVar('topic'); $sess_handler->clearVars(); $ts =& XsnsTextSanitizer::getInstance(); $default = array( 'name' => isset($topic_temp['name']) ? $ts->makeTboxData4PreviewInForm($topic_temp['name']) : '', 'body' => isset($topic_temp['body']) ? $ts->makeTareaData4PreviewInForm($topic_temp['body']) : '', ); $commu_info = array('id' => $cid, 'name' => $community->getVar('name')); $this->context->setAttribute('commu', $commu_info); $this->context->setAttribute('default', $default); }
function dispatch() { global $xoopsUser; if($this->isGuest() || !$this->validateToken('TOPIC_DELETE')){ redirect_header(XOOPS_URL, 2, _NOPERM); } $own_uid = $xoopsUser->getVar('uid'); $tcid = $this->getIntRequest('tcid'); if(!isset($tcid)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $commu_handler =& XsnsCommunityHandler::getInstance(); $topic_handler =& XsnsTopicHandler::getInstance(); $comment_handler =& XsnsTopicCommentHandler::getInstance(); // コメントの取得 $comment =& $comment_handler->get($tcid); if(!is_object($comment)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $tid = $comment->getVar('c_commu_topic_id'); $num = $comment->getNumber(); // トピックの取得 $topic =& $topic_handler->get($tid); if(!is_object($topic)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $topic_uid = $topic->getVar('uid'); // コミュニティの取得 $cid = $topic->getVar('c_commu_id'); $community =& $commu_handler->get($cid); if(!is_object($community)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $commu_auth = $community->getAuthority(); if($commu_auth < XSNS_AUTH_MEMBER){ redirect_header(XOOPS_URL, 2, _NOPERM); } $comment_uid = $comment->getVar('uid'); if($comment_uid < 1 || ($commu_auth < XSNS_AUTH_SUB_ADMIN && $own_uid != $comment_uid && $own_uid != $topic_uid)){ redirect_header(XOOPS_URL, 2, _NOPERM); } if($num > 0){ // コメントの削除 ・・・ 投稿者・本文データのみ削除する $comment->setVar('uid', 0); $comment->setVar('body', ''); if($comment_handler->insert($comment)){ // コメントに添付された画像・ファイルを削除 $criteria = new CriteriaCompo(new Criteria('target', 2)); $criteria->add(new Criteria('target_id', $tcid)); $image_handler =& XsnsImageHandler::getInstance(); $image_handler->deleteObjects($criteria); $file_handler =& XsnsFileHandler::getInstance(); $file_handler->deleteObjects($criteria); redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, _MD_XSNS_TOPIC_DEL_RES_OK); } redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, _MD_XSNS_TOPIC_DEL_RES_NG); } else{ // トピックの削除 ・・・ トピックおよびコメントを完全に削除する if($topic->deleteCommentsAll() && $topic_handler->delete($topic)){ redirect_header(XSNS_URL_COMMU.'?cid='.$cid, 2, _MD_XSNS_TOPIC_DEL_OK); } redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, _MD_XSNS_TOPIC_DEL_NG); } }
function dispatch() { global $xoopsUser; if($this->isGuest() || !$this->validateToken('TOPIC_COMMENT_ADD')){ redirect_header(XOOPS_URL, 2, _NOPERM); } $own_uid = $xoopsUser->getVar('uid'); $tid = $this->getIntRequest('tid'); if(!isset($tid)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $body = $this->getTextRequest('comment_body', XSNS_REQUEST_SESSION); if(!isset($body)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $commu_handler =& XsnsCommunityHandler::getInstance(); $topic_handler =& XsnsTopicHandler::getInstance(); $comment_handler =& XsnsTopicCommentHandler::getInstance(); // トピックの取得 $topic =& $topic_handler->get($tid); if(!is_object($topic) || $topic->getCommentCount() >= 1001){ redirect_header(XOOPS_URL, 2, _NOPERM); } // コミュニティの取得 $cid = $topic->getVar('c_commu_id'); $community =& $commu_handler->get($cid); if(!is_object($community)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $commu_auth = $community->getAuthority(); if($commu_auth < XSNS_AUTH_NON_MEMBER || ($commu_auth < XSNS_AUTH_MEMBER && $community->getVar('public_flag')==3) ){ redirect_header(XOOPS_URL, 2, _NOPERM); } // コメントの投稿 $new_comment =& $comment_handler->create(); $new_comment->setVars(array( 'c_commu_topic_id' => $tid, 'c_commu_id' => $cid, 'uid' => $own_uid, 'body' => $body, 'r_datetime' => date('Y-m-d H:i:s'), 'r_date' => date('Y-m-d'), 'number' => $topic->getCommentCount(), )); if($tcid = $comment_handler->insert($new_comment)){ // 画像のアップロード $image_handler =& XsnsImageHandler::getInstance(); $image_handler->uploadImage('t', 2, $tcid); // ファイルのアップロード $file_handler =& XsnsFileHandler::getInstance(); $file_handler->uploadFile('t', 2, $tcid); // イベント通知 if(include_once(XSNS_TRUST_PATH.'/include/notification.php')){ $tags = array( 'COMMU_NAME' => $community->getVar('name'), 'TOPIC_NAME' => $topic->getVar('name'), 'TOPIC_BODY' => $new_comment->getVar('body', 'e'), // disallow HTML 'AUTHOR_NAME' => $xoopsUser->getVar('uname'), 'TOPIC_URI' => XSNS_URL_TOPIC.'&tid='.$tid, ); // コミュニティメンバー以外には送信しない $c_member_obj_list =& $community->getMemberObjects(); $c_member_ids = array(); foreach($c_member_obj_list as $c_member_obj){ $c_member_ids[] = $c_member_obj->getVar('uid'); } xsns_main_trigger_event('topic', $cid, 'post', $tags, $c_member_ids); } $xoopsUser->incrementPost(); $sess_handler =& XsnsSessionHandler::getInstance(); $sess_handler->clearVars(); redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, _MD_XSNS_TOPIC_ADD_RES_OK); } redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, _MD_XSNS_TOPIC_ADD_RES_NG); }
function checkAuthority($image_id, $file_id) { global $xoopsUser, $xoopsUserIsAdmin; if($xoopsUserIsAdmin){ return true; } if($this->isGuest()){ return false; } $own_uid = $xoopsUser->getVar('uid'); if($image_id > 0){ $image_handler =& XsnsImageHandler::getInstance(); $data =& $image_handler->get($image_id); } elseif($file_id > 0){ $file_handler =& XsnsFileHandler::getInstance(); $data =& $file_handler->get($file_id); } else{ return false; } if(!is_object($data)){ return false; } $target = $data->getVar('target'); $target_id = $data->getVar('target_id'); $commu_handler =& XsnsCommunityHandler::getInstance(); $c_member_handler =& XsnsMemberHandler::getInstance(); if($target == 1){ // for community $community =& $commu_handler->get($target_id); if(!is_object($community)){ return false; } $c_member =& $c_member_handler->getOne($target_id, $own_uid); if(!is_object($c_member)){ return false; } if($own_uid == $community->getVar('uid_admin')){ // admin only return true; } } elseif($target == 2){ // for topic/comment $comment_handler =& XsnsTopicCommentHandler::getInstance(); $comment =& $comment_handler->get($target_id); if(!is_object($comment)){ return false; } $tid = $comment->getVar('c_commu_topic_id'); $topic_handler =& XsnsTopicHandler::getInstance(); $topic =& $topic_handler->get($tid); if(!is_object($topic)){ return false; } $cid = $comment->getVar('c_commu_id'); $community =& $commu_handler->get($cid); if(!is_object($community)){ return false; } $c_member =& $c_member_handler->getOne($cid, $own_uid); if(!is_object($c_member)){ return false; } if($own_uid == $comment->getVar('uid') || $own_uid == $topic->getVar('uid') || $own_uid == $community->getVar('uid_admin') || $own_uid == $community->getVar('uid_sub_admin')){ return true; } } return false; }
function dispatch() { global $xoopsUser; $own_uid = is_object($xoopsUser)? $xoopsUser->getVar('uid') : 0; $limit = 20; $tid = $this->getIntRequest('tid', XSNS_REQUEST_GET); if(!isset($tid)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $start = $this->getIntRequest('s', XSNS_REQUEST_GET); $commu_handler =& XsnsCommunityHandler::getInstance(); $topic_handler =& XsnsTopicHandler::getInstance(); $user_handler =& XsnsUserHandler::getInstance(); $image_handler =& XsnsImageHandler::getInstance(); $file_handler =& XsnsFileHandler::getInstance(); // トピックの取得 $topic =& $topic_handler->get($tid); if(!is_object($topic)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $topic_uid = $topic->getVar('uid'); // コミュニティの取得 $cid = $topic->getVar('c_commu_id'); $community =& $commu_handler->get($cid); if(!is_object($community) || ($community->getVar('public_flag')==3 && !$community->checkAuthority())){ redirect_header(XOOPS_URL, 2, _NOPERM); } $main_comment =& $topic->getCommentList(1, 0); if(!is_array($main_comment) || !isset($main_comment[0])){ redirect_header(XOOPS_URL, 2, _NOPERM); } $comment_count_all = $topic->getCommentCount() - 1; if($comment_count_all > 1000){ $comment_count_all = 1000; } if($comment_count_all > 0){ if(!isset($start) || $start < 0 || $start > 1000){ $start = $limit * floor(($comment_count_all-1)/$limit); } if($start >= 1000){ $start = 1000 - $limit; } } else{ $start = 0; } $comment_list_temp =& $topic->getCommentList($limit, $start+1); // except No.0 if(is_array($comment_list_temp)){ $comment_list_temp = $main_comment + $comment_list_temp; } else{ $comment_list_temp = $main_comment; } $sess_handler =& XsnsSessionHandler::getInstance(); $comment_temp = $sess_handler->getVar('comment_body'); $sess_handler->clearVars(); $ts =& XsnsTextSanitizer::getInstance(); $default = array( 'comment' => !empty($comment_temp) ? $ts->makeTboxData4PreviewInForm($comment_temp) : '', ); // 引用レスのポップアップウィンドウ生成 ---------------- $res_ids_temp = array(); $this->vars = array( 'comment_list' => array(), 'comment_checked' => array(), 'res_depth' => 0, ); $this->vars['comment_list'] =& $comment_list_temp; foreach($comment_list_temp as $comment){ $this->vars['res_depth'] = 0; $res_ids_temp = $this->getResIds($tid, $comment['number'], $comment['body']); } if(is_array($this->vars['comment_checked'])){ $res_ids = array_keys($this->vars['comment_checked']); $res_list =& $this->getResList($tid, $res_ids); $res_popup_list =& $this->getResPopupList($limit, $res_ids, $res_list); } else{ $res_list = NULL; } //------------------------------------------------------ $comment_list = array(); $commu_auth = $community->getAuthority(); foreach($comment_list_temp as $comment){ $comment_ids[] = $comment['c_commu_topic_comment_id']; } $image_list =& $image_handler->getListByIds(2, $comment_ids); $file_list =& $file_handler->getListByIds(2, $comment_ids); $author_obj_list = array(); foreach($comment_list_temp as $comment){ $comment_uid = intval($comment['uid']); if($comment_uid > 0){ $tcid = intval($comment['c_commu_topic_comment_id']); if(!isset($author_obj_list[$comment_uid])){ $author_obj_list[$comment_uid] =& $user_handler->get($comment_uid); } if(is_object($author_obj_list[$comment_uid])){ $author_info =& $author_obj_list[$comment_uid]->getInfo(); } else{ $author_info = array(); } $id = intval($comment['c_commu_topic_comment_id']); $images = isset($image_list[$id]) ? $image_list[$id] : array(); $files = isset($file_list[$id]) ? $file_list[$id] : array(); $comment_list[] = array( 'uid' => $comment_uid, 'body' => $this->getResQuotedCommentBody($tid, $comment['number'], $res_list), 'author' => $author_info, 'time' => $comment['r_datetime'], 'number' => $comment['number'], 'images' => $images, 'files' => $files, 'show_edit' => $commu_auth>=XSNS_AUTH_SUB_ADMIN || ($commu_auth>=XSNS_AUTH_MEMBER && ($comment_uid==$own_uid || $topic_uid==$own_uid)), 'show_res_add' => ($commu_auth>=XSNS_AUTH_MEMBER), 'url_edit' => XSNS_URL_TOPIC.'&'.XSNS_ACTION_ARG.'=edit&tcid='.$tcid, 'url_del' => XSNS_URL_TOPIC.'&'.XSNS_ACTION_ARG.'=del&tcid='.$tcid, ); } else{ // deleted topic/comment $comment_list[] = array( 'uid' => 0, 'body' => '', 'time' => $comment['r_datetime'], 'number' => $comment['number'], ); } } $comment_count = count($comment_list) - 1; $pager = $this->getPageSelector(XSNS_URL_TOPIC.'&tid='.$tid, $start, $limit, $comment_count, $comment_count_all); $image_handler->DeleteImageTemp(); $file_handler->DeleteFileTemp(); $commu_vars = array( 'id' => $community->getVar('c_commu_id'), 'name' => $community->getVar('name'), 'auth_level' => $commu_auth, ); $topic_vars = array( 'id' => $tid, 'name' => $topic->getVar('name'), ); $this->context->setAttribute('commu', $commu_vars); $this->context->setAttribute('topic', $topic_vars); $this->context->setAttribute('comment_list', $comment_list); $this->context->setAttribute('comment_count', $comment_count); $this->context->setAttribute('comment_count_all', $comment_count_all); $this->context->setAttribute('pager', $pager); $this->context->setAttribute('res_popup_list', $res_popup_list); $this->context->setAttribute('default', array('body' => $default['comment'])); }
function dispatch() { if($this->isGuest()){ redirect_header(XOOPS_URL, 2, _NOPERM); } $tid = $this->getIntRequest('tid'); if(!isset($tid)){ redirect_header(XOOPS_URL, 2, _NOPERM); } require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; $token_handler = new XoopsMultiTokenHandler(); $token = new XoopsFormToken($token_handler->create('TOPIC_COMMENT_ADD')); // Hidden $token_tag = '<input type="hidden" name="'.$token->_name.'" value="'.$token->_value.'">'; $this->context->setAttribute('token_tag', $token_tag); $commu_handler =& XsnsCommunityHandler::getInstance(); $topic_handler =& XsnsTopicHandler::getInstance(); // トピックの取得 $topic =& $topic_handler->get($tid); if(!is_object($topic) || $topic->getCommentCount() >= 1001){ redirect_header(XOOPS_URL, 2, _NOPERM); } // コミュニティの取得 $cid = $topic->getVar('c_commu_id'); $community =& $commu_handler->get($cid); if(!is_object($community)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $commu_auth = $community->getAuthority(); if($commu_auth < XSNS_AUTH_NON_MEMBER || ($commu_auth < XSNS_AUTH_MEMBER && $community->getVar('public_flag')==3) ){ redirect_header(XOOPS_URL, 2, _NOPERM); } $errors = array(); $body = $this->getTextRequest('body'); if(empty($body)){ $errors[] = _MD_XSNS_TOPIC_RES_BODY_NG; } if(count($errors) > 0){ redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, _MD_XSNS_TOPIC_RES_BODY_NG); } $comment_handler =& XsnsTopicCommentHandler::getInstance(); $new_comment =& $comment_handler->create(); $new_comment->setVar('body', $body); $commu_vars = array('id' => $cid, 'name' => $community->getVar('name')); $sess_handler =& XsnsSessionHandler::getInstance(); $sess_handler->setVar('comment_body', $body); $image_handler =& XsnsImageHandler::getInstance(); $file_handler =& XsnsFileHandler::getInstance(); $topic_vars = array( 'id' => $tid, 'name' => $topic->getVar('name'), 'body' => preg_replace('/\[res\]([1-9]\\d*)\[\/res\]/', '>>\1', $new_comment->getVar('body', 'p')), 'images' => $image_handler->uploadImageTemp('images'), 'files' => $file_handler->uploadFileTemp('files'), ); $this->context->setAttribute('topic', $topic_vars); $this->context->setAttribute('commu', $commu_vars); }
function dispatch() { global $xoopsModuleConfig; $err = $this->checkPermission(); if(!is_array($err) || count($err) > 0){ $this->context->setAttribute('perm_error', $err); return "default"; } $limit = 10; $start = $this->getIntRequest('s', XSNS_REQUEST_GET); if(!isset($start) || $start<0){ $start = 0; } $criteria = new CriteriaCompo(NULL); $criteria->setLimit($limit); $criteria->setStart($start); $criteria->setSort('c_file_id'); $criteria->setOrder('DESC'); $file_handler =& XsnsFileHandler::getInstance(); $file_obj_list =& $file_handler->getObjects($criteria); $file_list = array(); $user_handler =& xoops_gethandler('user'); $comment_handler =& XsnsTopicCommentHandler::getInstance(); $comment = array(); foreach($file_obj_list as $file_obj){ $file_id = $file_obj->getVar('c_file_id'); $filename = $file_obj->getVar('filename'); $file_path = $xoopsModuleConfig['file_upload_path']. '/'. $filename; $file_info = @stat($file_path); $author_obj =& $user_handler->get($file_obj->getVar('uid')); $author_name = is_object($author_obj) ? $author_obj->getVar('uname') : ""; $page_url = ""; $target = $file_obj->getVar('target'); $target_id = $file_obj->getVar('target_id'); if($target==1){ $page_url = XSNS_URL_COMMU.'?cid='.$target_id; } elseif($target==2){ if(!isset($comment[$target_id])){ $comment[$target_id] =& $comment_handler->get($target_id); } if(is_object($comment[$target_id])){ $page_url = XSNS_URL_TOPIC.'&tid='.$comment[$target_id]->getVar('c_commu_topic_id'); } } $file_list[$file_id] = array( 'id' => $file_id, 'url' => XSNS_FILE_URL."?id=".$file_id, 'ref_link' => empty($page_url) ? "-" : "<a href='".$page_url."' target='_blank'>URL</a>", 'filename' => rawurldecode($file_obj->getVar('org_filename')), 'author' => $author_name, 'size' => number_format($file_info['size']), 'time' => str_replace(" ", "<br>", date('Y-m-d H:i:s', $file_info['mtime'])), 'active' => "checked", ); unset($author_obj); } $pager = $this->getPageSelector('index.php?'.XSNS_ACTION_ARG.'=file', $start, $limit, count($file_list), $file_handler->getCount(), "#FFCCCC"); $this->context->setAttribute('file_list', $file_list); $this->context->setAttribute('pager', $pager); }
function dispatch() { if($this->isGuest()){ redirect_header(XOOPS_URL, 2, _NOPERM); } require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; $token_handler = new XoopsMultiTokenHandler(); $token = new XoopsFormToken($token_handler->create('TOPIC_ADD')); // Hidden $token_tag = '<input type="hidden" name="'.$token->_name.'" value="'.$token->_value.'">'; $this->context->setAttribute('token_tag', $token_tag); $cid = $this->getIntRequest('cid'); if(!isset($cid)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $commu_handler =& XsnsCommunityHandler::getInstance(); $topic_handler =& XsnsTopicHandler::getInstance(); $comment_handler =& XsnsTopicCommentHandler::getInstance(); $sess_handler =& XsnsSessionHandler::getInstance(); $image_handler =& XsnsImageHandler::getInstance(); $file_handler =& XsnsFileHandler::getInstance(); // コミュニティの取得 $community =& $commu_handler->get($cid); if(!is_object($community) || !$community->checkAuthority()){ redirect_header(XOOPS_URL, 2, _NOPERM); } $param = array( 'number' => 0, 'name' => $this->getTextRequest('name'), 'body' => $this->getTextRequest('body'), ); $errors = array(); $this->checkParam(&$param, &$errors); $new_topic =& $topic_handler->create(); $new_topic->setVar('name', $param['name']); $new_comment =& $comment_handler->create(); $new_comment->setVar('body', $param['body']); $commu_vars = array('id' => $cid, 'name' => $community->getVar('name')); // 入力エラー if(count($errors) > 0){ $default = array( 'name' => $new_topic->getVar('name', 'f'), 'body' => $new_comment->getVar('body', 'f'), ); $this->context->setAttribute('commu', $commu_vars); $this->context->setAttribute('default', $default); $this->context->setAttribute('errors', $errors); return "add"; // → topic/addView.php } $topic_vars_temp = array( 'name' => $param['name'], 'body' => $param['body'], ); $sess_handler->setVar('topic', $topic_vars_temp); $topic_vars = array( 'name' => $new_topic->getVar('name', 'p'), 'body' => $new_comment->getVar('body', 'p'), 'images' => $image_handler->uploadImageTemp('images'), 'files' => $file_handler->uploadFileTemp('files'), ); $this->context->setAttribute('topic', $topic_vars); $this->context->setAttribute('commu', $commu_vars); }
function &getListForCommunity($cid, $limit=0, $start=0, $get_body=false) { $ts =& XsnsTextSanitizer::getInstance(); $image_handler =& XsnsImageHandler::getInstance(); $file_handler =& XsnsFileHandler::getInstance(); $ret = array(); $base_url = XSNS_URL_TOPIC.'&tid='; $sql = "SELECT ". "ct.c_commu_topic_id AS tid,". "ct.name AS tname,". "MAX(ctc.r_datetime) AS max_r_datetime,". "ctc.c_commu_topic_comment_id AS tcid,". "COUNT(*) AS comment_count". " FROM ". $this->prefix('c_commu_topic_comment'). " ctc". " INNER JOIN ". $this->prefix('c_commu_topic'). " ct". " USING(c_commu_topic_id)". " WHERE ct.c_commu_id='".intval($cid)."'". " GROUP BY ctc.c_commu_topic_id". " ORDER BY max_r_datetime DESC"; $rs = $this->db->query($sql, $limit, $start); if(!$rs){ return $ret; } if($get_body){ $comment_handler =& XsnsTopicCommentHandler::getInstance(); while($row = $this->db->fetchArray($rs)){ $comment =& $comment_handler->getByNumber($row['tid'], 0); $ret[] = array( 'name' => $ts->makeTboxData4Show($row['tname']), 'time' => XsnsUtils::getUserTimestamp($row['max_r_datetime']), 'page_url' => $base_url. intval($row['tid']), 'comment_count' => intval($row['comment_count'])-1, // except comment No.0 'body' => $comment->getVar('body'), 'images' => $image_handler->getList(2, intval($row['tcid'])), 'files' => $file_handler->getList(2, intval($row['tcid'])), ); unset($comment); } } else{ while($row = $this->db->fetchArray($rs)){ $ret[] = array( 'name' => $ts->makeTboxData4Show($row['tname']), 'time' => XsnsUtils::getUserTimestamp($row['max_r_datetime']), 'page_url' => $base_url. intval($row['tid']), 'comment_count' => intval($row['comment_count'])-1, // except comment No.0 'body' => '', ); unset($comment); } } return $ret; }
function dispatch() { global $xoopsUser; if($this->isGuest() || !$this->validateToken('TOPIC_EDIT')){ redirect_header(XOOPS_URL, 2, _NOPERM); } $own_uid = $xoopsUser->getVar('uid'); $tcid = $this->getIntRequest('tcid'); $commu_handler =& XsnsCommunityHandler::getInstance(); $topic_handler =& XsnsTopicHandler::getInstance(); $comment_handler =& XsnsTopicCommentHandler::getInstance(); $image_handler =& XsnsImageHandler::getInstance(); $file_handler =& XsnsFileHandler::getInstance(); // コメントの取得 $comment =& $comment_handler->get($tcid); if(!is_object($comment)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $tid = $comment->getVar('c_commu_topic_id'); // トピックの取得 $topic =& $topic_handler->get($tid); if(!is_object($topic)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $cid = $topic->getVar('c_commu_id'); // コミュニティの取得 $community =& $commu_handler->get($topic->getVar('c_commu_id')); if(!is_object($community)){ redirect_header(XOOPS_URL, 2, _NOPERM); } $commu_auth = $community->getAuthority(); if($commu_auth < XSNS_AUTH_MEMBER){ redirect_header(XOOPS_URL, 2, _NOPERM); } $param = array( 'number' => $comment->getNumber(), 'name' => $this->getTextRequest('name'), 'body' => $this->getTextRequest('body'), ); $errors = array(); $this->checkParam(&$param, &$errors); $temp_topic =& $topic_handler->create(); $temp_topic->setVars(array( 'name' => $param['name'], )); $temp_comment =& $comment_handler->create(); $temp_comment->setVar('body', $param['body']); if(count($errors) > 0){ $topic_name = $temp_topic->getVar('name', 'e'); $topic_vars = array( 'id' => $tid, 'tcid' => $tcid, 'name' => empty($topic_name) ? $topic->getVar('name', 'e') : $topic_name, ); $comment_body = $temp_comment->getVar('body', 'e'); $comment_vars = array( 'number' => $param['number'], 'body' => empty($comment_body) ? $comment->getVar('body', 'e') : $comment_body, 'images' => $comment->getImageList(2, XSNS_IMAGE_SIZE_S), 'files' => $comment->getFileList(2), ); $commu_vars = array( 'id' => $cid, 'name' => $community->getVar('name'), ); $this->context->setAttribute('topic', $topic_vars); $this->context->setAttribute('commu', $commu_vars); $this->context->setAttribute('comment', $comment_vars); $this->context->setAttribute('errors', $errors); return "edit"; // → topic/editView.php } $topic_uid = $topic->getVar('uid'); $comment_uid = $comment->getVar('uid'); if($comment_uid > 0 && ($own_uid == $topic_uid || $own_uid == $comment_uid || $commu_auth >= XSNS_AUTH_SUB_ADMIN)){ $r_datetime = date('Y-m-d H:i:s'); // $r_date = date('Y-m-d'); $topic->setVars(array( 'name' => $param['name'], // 'r_datetime' => $r_datetime, // naao 編集時に、トピ日時を更新しない // 'r_date' => $r_date, )); if($topic_handler->insert($topic)){ $tcid = $comment->getVar('c_commu_topic_comment_id'); if($image_handler->uploadImageTemp('images')){ $image_handler->uploadImage('t', 2, $tcid); } if($file_handler->uploadFileTemp('files')){ $file_handler->uploadFile('t', 2, $tcid); } $comment->setVars(array( 'body' => $param['body'], 'number' => $param['number'], // 'r_datetime' => $r_datetime, // naao 編集時に、トピ日時を更新しない // 'r_date' => $r_date, )); if($comment_handler->insert($comment)){ $msg = ($param['number']==0)? _MD_XSNS_TOPIC_EDIT_OK : _MD_XSNS_TOPIC_EDIT_RES_OK; } else{ $msg = ($param['number']==0)? _MD_XSNS_TOPIC_EDIT_NG : _MD_XSNS_TOPIC_EDIT_RES_NG; } } else{ $msg = _MD_XSNS_TOPIC_EDIT_NG; } redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, $msg); } redirect_header(XOOPS_URL, 2, _NOPERM); }
function dispatch() { global $xoopsUser; if($this->isGuest() || !$this->validateToken('TOPIC_ADD')){ redirect_header(XOOPS_URL, 2, _NOPERM); } $own_uid = $xoopsUser->getVar('uid'); $cid = $this->getIntRequest('cid'); if(!isset($cid)){ redirect_header(XOOPS_URL, 2, _NOPERM); } // コミュニティの取得 $commu_handler =& XsnsCommunityHandler::getInstance(); $community =& $commu_handler->get($cid); if(!is_object($community) || !$community->checkAuthority()){ redirect_header(XOOPS_URL, 2, _NOPERM); } $sess_handler =& XsnsSessionHandler::getInstance(); $topic = $sess_handler->getVar('topic'); if(!is_array($topic) || !isset($topic['name']) || !isset($topic['body'])){ redirect_header(XOOPS_URL, 2, _NOPERM); } $r_datetime = date('Y-m-d H:i:s'); $r_date = date('Y-m-d'); $topic_handler =& XsnsTopicHandler::getInstance(); $new_topic =& $topic_handler->create(); $new_topic->setVars(array( 'c_commu_id' => $cid, 'name' => $topic['name'], 'r_datetime' => $r_datetime, 'r_date' => $r_date, 'uid' => $own_uid, )); if($tid = $topic_handler->insert($new_topic)){ $comment_handler =& XsnsTopicCommentHandler::getInstance(); $new_comment =& $comment_handler->create(); $new_comment->setVars(array( 'c_commu_topic_id' => $tid, 'c_commu_id' => $cid, 'uid' => $own_uid, 'body' => $topic['body'], 'r_datetime' => $r_datetime, 'r_date' => $r_date, 'number' => 0, )); if($tcid = $comment_handler->insert($new_comment)){ // トピックのコメントに対して画像を添付 $image_handler =& XsnsImageHandler::getInstance(); $image_ids = $image_handler->uploadImage('t', 2, $tcid); // トピックのコメントに対してファイルを添付 $file_handler =& XsnsFileHandler::getInstance(); $file_ids = $file_handler->uploadFile('t', 2, $tcid); // イベント通知 if(include_once(XSNS_TRUST_PATH.'/include/notification.php')){ $tags = array( 'COMMU_NAME' => $community->getVar('name'), 'TOPIC_NAME' => $new_topic->getVar('name'), 'TOPIC_BODY' => $new_comment->getVar('body', 'e'), // disallow HTML 'AUTHOR_NAME' => $xoopsUser->getVar('uname'), 'TOPIC_URI' => XSNS_URL_TOPIC.'&tid='.$tid, ); // コミュニティメンバー以外には送信しない $c_member_obj_list =& $community->getMemberObjects(); $c_member_ids = array(); foreach($c_member_obj_list as $c_member_obj){ $c_member_ids[] = $c_member_obj->getVar('uid'); } xsns_main_trigger_event('topic', $cid, 'create', $tags, $c_member_ids); } $xoopsUser->incrementPost(); $sess_handler->clearVars(); redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, _MD_XSNS_TOPIC_ADD_OK); } } redirect_header(XSNS_URL_TOPIC.'&'.XSNS_ACTION_ARG.'=add&cid='.$cid, 2, _MD_XSNS_TOPIC_ADD_NG); }