// the picture is commentable if it belongs at least to one category which
// is commentable
$page['show_comments'] = false;
foreach ($related_categories as $category) {
    if ($category['commentable'] == 'true') {
        $page['show_comments'] = true;
        break;
    }
}
if ($page['show_comments'] and isset($_POST['content'])) {
    if (is_a_guest() and !$conf['comments_forall']) {
        die('Session expired');
    }
    $comm = array('author' => trim(@$_POST['author']), 'content' => trim($_POST['content']), 'website_url' => trim(@$_POST['website_url']), 'email' => trim(@$_POST['email']), 'image_id' => $page['image_id']);
    include_once PHPWG_ROOT_PATH . 'include/functions_comment.inc.php';
    $comment_action = insert_user_comment($comm, @$_POST['key'], $page['errors']);
    switch ($comment_action) {
        case 'moderate':
            $page['infos'][] = l10n('An administrator must authorize your comment before it is visible.');
        case 'validate':
            $page['infos'][] = l10n('Your comment has been registered');
            break;
        case 'reject':
            set_status_header(403);
            $page['errors'][] = l10n('Your comment has NOT been registered because it did not pass the validation rules');
            break;
        default:
            trigger_error('Invalid comment action ' . $comment_action, E_USER_WARNING);
    }
    // allow plugins to notify what's going on
    trigger_notify('user_comment_insertion', array_merge($comm, array('action' => $comment_action)));
Example #2
0
/**
 * API method
 * Adds a comment to an image
 * @param mixed[] $params
 *    @option int image_id
 *    @option string author
 *    @option string content
 *    @option string key
 */
function ws_images_addComment($params, $service)
{
    $query = '
SELECT DISTINCT image_id
  FROM ' . IMAGE_CATEGORY_TABLE . '
      INNER JOIN ' . CATEGORIES_TABLE . ' ON category_id=id
  WHERE commentable="true"
    AND image_id=' . $params['image_id'] . get_sql_condition_FandF(array('forbidden_categories' => 'id', 'visible_categories' => 'id', 'visible_images' => 'image_id'), ' AND') . '
;';
    if (!pwg_db_num_rows(pwg_query($query))) {
        return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid image_id');
    }
    $comm = array('author' => trim($params['author']), 'content' => trim($params['content']), 'image_id' => $params['image_id']);
    include_once PHPWG_ROOT_PATH . 'include/functions_comment.inc.php';
    $comment_action = insert_user_comment($comm, $params['key'], $infos);
    switch ($comment_action) {
        case 'reject':
            $infos[] = l10n('Your comment has NOT been registered because it did not pass the validation rules');
            return new PwgError(403, implode("; ", $infos));
        case 'validate':
        case 'moderate':
            $ret = array('id' => $comm['id'], 'validation' => $comment_action == 'validate');
            return array('comment' => new PwgNamedStruct($ret));
        default:
            return new PwgError(500, "Unknown comment action " . $comment_action);
    }
}