public static function addComment($issueGuid, $comment, $userId)
 {
     global $wpdb;
     $postId = $wpdb->get_var($wpdb->prepare("SELECT post_id\n            FROM {$wpdb->postmeta}\n            WHERE meta_key = 'guid' AND meta_value = %s", $issueGuid));
     if (isset($postId) && $postId != '') {
         $issue = get_post($postId);
         $authorized = false;
         $user = get_user_by('id', $userId);
         $options = BIMBCFManagement::getOptions();
         $assignedTo = get_post_meta($issue->ID, 'assigned_to', true);
         if ($issue->post_author == $userId || $user->user_email == $assignedTo) {
             $authorized = true;
         }
         $uri = get_post_meta($issue->ID, '_bimsie_uri', true);
         $poids = get_post_meta($issue->ID, 'poid');
         // We have not published this issue and it is not assigned to us
         // Check if we have access to at least one of its project(s)
         if (!$authorized) {
             foreach ($poids as $poid) {
                 $project = BIMsie::getProject($uri, $poid, $userId);
                 if ($project) {
                     $authorized = true;
                     break;
                 }
             }
         }
         if ($issue->post_type == $options['bcf_issue_post_type'] && $authorized) {
             if (!isset($comment['VerbalStatus'])) {
                 $comment['VerbalStatus'] = '';
             }
             if (!isset($comment['Status'])) {
                 $comment['Status'] = '';
             }
             if (!isset($comment['Date'])) {
                 $comment['Date'] = date('Y-m-d\\TH:i:sP');
             }
             if (!isset($comment['Author'])) {
                 $comment['Author'] = $user->user_email;
             }
             if (!isset($comment['Comment'])) {
                 $comment['Comment'] = '';
             }
             if (!isset($comment['Topic'])) {
                 $comment['Topic'] = array();
             }
             if (!isset($comment['ModifiedDate'])) {
                 $comment['ModifiedDate'] = date('Y-m-d\\TH:i:sP');
             }
             if (!isset($comment['Priority'])) {
                 $comment['Priority'] = '';
             }
             $topicStatuses = explode(',', $options['topic_statuses']);
             $priorities = explode(',', $options['priorities']);
             $markup = get_post_meta($postId, 'markup', true);
             if (!in_array($comment['VerbalStatus'], $topicStatuses)) {
                 $comment['VerbalStatus'] = isset($topicStatuses[0]) ? $topicStatuses[0] : '';
             }
             if (!in_array($comment['Priority'], $priorities)) {
                 $comment['Priority'] = isset($priorities[0]) ? $priorities[0] : '';
             }
             $markup['Comment'][] = $comment;
             update_post_meta($issue->ID, 'markup', $markup);
             $commentData = array('comment_post_ID' => $issue->ID, 'comment_author' => $comment['Author'], 'comment_author_email' => $comment['Author'], 'comment_author_url' => '', 'comment_content' => $comment['Comment'], 'comment_type' => '', 'comment_parent' => 0, 'user_id' => $userId, 'comment_author_IP' => '127.0.0.1', 'comment_agent' => 'BCF API', 'comment_date' => $comment['Date'], 'comment_approved' => 1);
             $commentData['comment_content'] = $commentData['comment_content'] . "\n" . __('Status', 'bim-bcf-management') . ': ' . $comment['Status'];
             $commentData['comment_content'] = $commentData['comment_content'] . "\n" . __('VerbalStatus', 'bim-bcf-management') . ': ' . $comment['VerbalStatus'];
             $commentData['comment_content'] = $commentData['comment_content'] . "\n" . __('Priority', 'bim-bcf-management') . ': ' . $comment['Priority'];
             wp_insert_comment($commentData);
             return BIMBCFManagement::getJSONFromIssue($issue);
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Beispiel #2
0
             $errorType = 'UserException';
             $errorMessage = __('Invalid token', 'bim-bcf-management');
         }
     } else {
         $invalid = true;
         $errorType = 'InvalidRequest';
         $errorMessage = __('Unsupported interface or method, check supported methods by browsing to: ', 'bim-bcf-management') . plugins_url('api.php', __FILE__);
     }
 } elseif ($request['request']['method'] == 'addIssue') {
     $userId = BIMsie::getUserIdByToken(isset($request['token']) ? $request['token'] : '');
     if ($userId !== false) {
         if (isset($request['request']['parameters']['issue'])) {
             $result = BIMBCFManagement::addIssue($request['request']['parameters']['issue'], $userId);
             if ($result !== false) {
                 $issue = get_post($result);
                 $result = BIMBCFManagement::getJSONFromIssue($issue);
             }
         } else {
             $invalid = true;
             $errorType = 'InvalidRequest';
             $errorMessage = __('Unsupported interface or method, check supported methods by browsing to: ', 'bim-bcf-management') . plugins_url('api.php', __FILE__);
         }
     } else {
         $invalid = true;
         $errorType = 'UserException';
         $errorMessage = __('Invalid token', 'bim-bcf-management');
     }
 } elseif ($request['request']['method'] == 'getExtensions') {
     $userId = BIMsie::getUserIdByToken(isset($request['token']) ? $request['token'] : '');
     if ($userId !== false) {
         $options = BIMBCFManagement::getOptions();