public function post($route, $form)
 {
     global $user;
     if ($route == 'comments.json') {
         $options = $this->getOptions();
         $node = node_load($options['nid']);
         if ($options['uid'] != $user->uid || !is_object($node)) {
             return false;
         }
         // Should we let the comment pass ?
         if ($node->comment != COMMENT_NODE_OPEN || !user_access('post comments')) {
             // Access denied.
             return false;
         }
         if (!empty($form->values['cid'])) {
             $comment = comment_load($form->values['cid']);
             if (!is_object($comment)) {
                 // Not existent CID.. Access denied
                 return false;
             }
             $nodeSubmittedComment = node_load($comment->nid);
             if (!is_object($nodeSubmittedComment) || $nodeSubmittedComment->nid != $node->nid) {
                 return FALSE;
                 // BAD nid.. Or node non existent
             }
             // Publish
             if ($form->values['toPublish']) {
                 if (user_access('administer comments') && user_access('post comments')) {
                     $comment->status = COMMENT_PUBLISHED;
                     comment_save($comment);
                 }
                 return;
             }
             // Deletion
             if ($form->values['toDelete']) {
                 if (user_access('administer comments') && user_access('post comments')) {
                     comment_delete($comment->cid);
                 }
                 return;
             }
             if (!comment_access('edit', $comment)) {
                 return FALSE;
                 // No access to edit the comment.
             }
         }
         if (empty($comment)) {
             $pid = NULL;
             if (!empty($form->values['pid'])) {
                 if ($form->values['pid'] == (int) $form->values['pid']) {
                     if ($comment_parent = comment_load((int) $form->values['pid'])) {
                         $pid = $form->values['pid'];
                     }
                 }
             }
             $comment = new stdClass();
             $comment->nid = $node->nid;
             $comment->pid = $pid;
             $comment->uid = $user->uid;
             $comment->name = check_plain($form->values['author']);
         }
         $comment->subject = check_plain($form->values['subject']);
         $field = field_info_field('comment_body');
         $langcode = field_is_translatable('comment', $field) ? entity_language('comment', $comment) : LANGUAGE_NONE;
         $field_infos = field_info_instance('comment', 'comment_body', 'comment_node_' . $node->type);
         $format = $options['comment-body-format'];
         $text_processing = $field_infos['settings']['text_processing'];
         $body = $form->values['body'];
         $body = $format != 'plain_text' && $text_processing ? check_markup($body, $format) : check_plain($body);
         if ($text_processing) {
             $comment->comment_body[$langcode][0]['format'] = $format;
         }
         $comment->comment_body = array($langcode => array());
         $comment->comment_body[$langcode][0]['value'] = $body;
         comment_submit($comment);
         comment_save($comment);
         cache_clear_all();
     }
 }
 public function actionAddComt()
 {
     $comtback = new comtback();
     if (isset($_POST['newsid']) & isset($_POST['comtuserid']) & isset($_POST['parentcomtid']) & isset($_POST['comtcontent'])) {
         //用户积分修改
         $u = user_load($_POST['comtuserid']);
         $edit = array('field_jifen' => array('und' => array(0 => array('value' => $u->field_jifen['und'][0]['value'] + 2))));
         user_save($u, $edit);
         //drupal新增评论
         $comment = (object) array('nid' => $_POST['newsid'], 'cid' => 0, 'pid' => $_POST['parentcomtid'], 'uid' => $_POST['comtuserid'], 'mail' => '', 'is_anonymous' => 0, 'homepage' => '', 'status' => 0, 'subject' => $_POST['comtcontent'], 'language' => LANGUAGE_NONE);
         comment_submit($comment);
         comment_save($comment);
         $comtback->comtid = $comment->cid;
         $comtback->comtcontent = $comment->subject;
         $comtback->error_code = 0;
         if ($_POST['parentcomtid'] != 0) {
             //评论别人的评论
             $cominfo = new Cominfo();
             $cominfo->uid = $_POST['comtuserid'];
             $cominfo->nid = $_POST['newsid'];
             /*
             $user=user_load($_POST['comtuserid']);
             //评论人头像
             if($user->picture->uri=="")
             	$cominfo->upic=BigImg.'user/basic.png';
             else
                 $cominfo->upic=str_replace("public://",BigImg,$user->picture->uri);
             //评论人昵称
             $cominfo->uname=$user->name;
             */
             //评论内容
             $cominfo->ucontent = $_POST['comtcontent'];
             //父评论
             $pcomment = comment_load($_POST['parentcomtid']);
             //父评论内容
             //$cominfo->tocontent=$pcomment->subject;
             //父评论的所有者id
             $cominfo->toid = $pcomment->uid;
             $cominfo->save(false);
         }
     } else {
         $comtback->error_code = 1;
         $comtback->error_msg = "no enough input parameters";
     }
     $jsonObj = CJSON::encode($comtback);
     echo $jsonObj;
 }
Example #3
0
function bootstrap_theme_create_comment_form_submit(&$form, &$form_state)
{
    global $user;
    $comment_form = $form_state['values'];
    $comment = (object) array('nid' => $comment_form['nid'], 'uid' => $user->uid, 'mail' => '', 'is_anonymous' => FALSE, 'status' => COMMENT_PUBLISHED, 'language' => LANGUAGE_NONE, 'comment_body' => array(LANGUAGE_NONE => array(0 => array('value' => $comment_form['body'], 'format' => 'filtered_html'))));
    comment_submit($comment);
    comment_save($comment);
    drupal_set_message('Successfully created new comment.');
    $form_state['no_redirect'] = TRUE;
    $form_state['rebuild'] = TRUE;
    $form_state['programmed'] = FALSE;
}