• Publicity: Public Only All

general-comments-procs.tcl

Utility procs for general-comments

Location:
packages/general-comments/tcl/general-comments-procs.tcl
Created:
2000-10-12
Authors:
Phong Nguyen
Pascal Scheffers
CVS Identification:
$Id: general-comments-procs.tcl,v 1.25.2.8 2023/02/07 12:46:43 antoniop Exp $

Procedures in this file

Detailed information

general_comments::create_link (public, deprecated)

 general_comments::create_link object_id object_name return_url \
    link_text [ context_id ] [ category ]
Deprecated. Invoking this procedure generates a warning.

Generates an html link to add a comment to an object.

Parameters:
object_id - The object to comment on.
object_name - The name of the object.
return_url - A url for the user to return to after viewing a comment.
link_text - The text to display for the link.
context_id (optional)
category (optional) - A category to associate comment to.
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 ad_log_deprecated ad_log_deprecated (public) export_vars export_vars (public) general_comments_package_url general_comments_package_url (public) general_comments::create_link general_comments::create_link general_comments::create_link->ad_log_deprecated general_comments::create_link->export_vars general_comments::create_link->general_comments_package_url

Testcases:
No testcase defined.

general_comments::get_comments (public, deprecated)

 general_comments::get_comments object_id return_url
Deprecated. Invoking this procedure generates a warning.

Generates a line item list of comments for the object_id.

Parameters:
object_id - The object_id to retrieve the comments for.
return_url - A url for the user to return to after viewing a comment.
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 ad_log_deprecated ad_log_deprecated (public) db_foreach db_foreach (public) export_vars export_vars (public) general_comments_package_url general_comments_package_url (public) general_comments::get_comments general_comments::get_comments general_comments::get_comments->ad_log_deprecated general_comments::get_comments->db_foreach general_comments::get_comments->export_vars general_comments::get_comments->general_comments_package_url

Testcases:
No testcase defined.

general_comments_create_link (public)

 general_comments_create_link [ -object_name object_name ] \
    [ -link_text link_text ] [ -context_id context_id ] \
    [ -category category ] [ -link_attributes link_attributes ] \
    object_id [ return_url ]

Generates an html link to add a comment to an object.

Switches:
-object_name
(optional)
The name of the object.
-link_text
(defaults to "Add comment") (optional)
The text to display for the link.
-context_id
(optional)
The context_id for the comment.
-category
(optional)
A category to associate comment to.
-link_attributes
(optional)
Some additional parameters for the link. Could be used to set the link title and other things like that. Ex. -link_attributes { title="My link title" }
Parameters:
object_id - The object to comment on.
return_url (optional) - A url for the user to return to after viewing a comment.

Partial Call Graph (max 5 caller/called nodes):
%3 test_general_comments_create_link general_comments_create_link (test general-comments) general_comments_create_link general_comments_create_link test_general_comments_create_link->general_comments_create_link acs_object_name acs_object_name (public) general_comments_create_link->acs_object_name export_vars export_vars (public) general_comments_create_link->export_vars general_comments_package_url general_comments_package_url (public) general_comments_create_link->general_comments_package_url Class ::xowiki::includelet::my-general-comments Class ::xowiki::includelet::my-general-comments (public) Class ::xowiki::includelet::my-general-comments->general_comments_create_link packages/download/www/one-archive.tcl packages/download/ www/one-archive.tcl packages/download/www/one-archive.tcl->general_comments_create_link packages/download/www/one-revision.tcl packages/download/ www/one-revision.tcl packages/download/www/one-revision.tcl->general_comments_create_link packages/faq/www/one-faq.tcl packages/faq/ www/one-faq.tcl packages/faq/www/one-faq.tcl->general_comments_create_link packages/file-storage/www/file.tcl packages/file-storage/ www/file.tcl packages/file-storage/www/file.tcl->general_comments_create_link

Testcases:
general_comments_create_link

general_comments_delete_messages (public)

 general_comments_delete_messages -package_id package_id

Deletes all comments belonging to specified package.

Switches:
-package_id
(required)

Partial Call Graph (max 5 caller/called nodes):
%3 test_link_tests link_tests (test xowiki) general_comments_delete_messages general_comments_delete_messages test_link_tests->general_comments_delete_messages test_xowiki_test_cases xowiki_test_cases (test xowiki) test_xowiki_test_cases->general_comments_delete_messages content::item::delete content::item::delete (public) general_comments_delete_messages->content::item::delete db_list db_list (public) general_comments_delete_messages->db_list xowiki::before-uninstantiate xowiki::before-uninstantiate (public) xowiki::before-uninstantiate->general_comments_delete_messages

Testcases:
xowiki_test_cases, link_tests

general_comments_get_comments (public)

 general_comments_get_comments [ -print_content_p print_content_p ] \
    [ -print_attachments_p print_attachments_p ] \
    [ -print_user_info_p print_user_info_p ] \
    [ -context_id context_id ] \
    [ -my_comments_only_p my_comments_only_p ] object_id \
    [ return_url ]

Generates a line item list of comments for the object_id.

Switches:
-print_content_p
(defaults to "0") (optional)
Pass in 1 to print out content of comments.
-print_attachments_p
(defaults to "0") (optional)
Pass in 1 to print out attachments of comments, only works if print_content_p is 1.
-print_user_info_p
(defaults to "1") (optional)
-context_id
(optional)
Show only comments with given context_id
-my_comments_only_p
(defaults to "0") (optional)
Parameters:
object_id - The object_id to retrieve the comments for.
return_url (optional) - A url for the user to return to after viewing a comment.

Partial Call Graph (max 5 caller/called nodes):
%3 test_general_comments_create_retrieve general_comments_create_retrieve (test general-comments) general_comments_get_comments general_comments_get_comments test_general_comments_create_retrieve->general_comments_get_comments acs_package_root_dir acs_package_root_dir (public) general_comments_get_comments->acs_package_root_dir ad_conn ad_conn (public) general_comments_get_comments->ad_conn db_driverkey db_driverkey (public) general_comments_get_comments->db_driverkey db_multirow db_multirow (public) general_comments_get_comments->db_multirow export_vars export_vars (public) general_comments_get_comments->export_vars Class ::xowiki::includelet::my-general-comments Class ::xowiki::includelet::my-general-comments (public) Class ::xowiki::includelet::my-general-comments->general_comments_get_comments packages/download/www/one-archive.tcl packages/download/ www/one-archive.tcl packages/download/www/one-archive.tcl->general_comments_get_comments packages/download/www/one-revision.tcl packages/download/ www/one-revision.tcl packages/download/www/one-revision.tcl->general_comments_get_comments packages/faq/www/one-faq.tcl packages/faq/ www/one-faq.tcl packages/faq/www/one-faq.tcl->general_comments_get_comments packages/file-storage/www/file.tcl packages/file-storage/ www/file.tcl packages/file-storage/www/file.tcl->general_comments_get_comments

Testcases:
general_comments_create_retrieve

general_comments_new (public)

 general_comments_new -object_id object_id -comment_id comment_id \
    -title title -comment_mime_type comment_mime_type \
    -context_id context_id [ -user_id user_id ] \
    [ -creation_ip creation_ip ] -is_live is_live -category category \
    -content content

Creates a comment and attaches it to a given object ID

Switches:
-object_id
(required)
-comment_id
(required)
-title
(required)
-comment_mime_type
(required)
-context_id
(required)
-user_id
(optional)
-creation_ip
(optional)
-is_live
(required)
-category
(required)
-content
(required)
Returns:
Error:

Partial Call Graph (max 5 caller/called nodes):
%3 test_general_comments_create_retrieve general_comments_create_retrieve (test general-comments) general_comments_new general_comments_new test_general_comments_create_retrieve->general_comments_new acs_object_type acs_object_type (public) general_comments_new->acs_object_type ad_html_text_convert ad_html_text_convert (public) general_comments_new->ad_html_text_convert callback callback (public) general_comments_new->callback content::item::get_latest_revision content::item::get_latest_revision (public) general_comments_new->content::item::get_latest_revision db_dml db_dml (public) general_comments_new->db_dml packages/general-comments/www/comment-add-3.tcl packages/general-comments/ www/comment-add-3.tcl packages/general-comments/www/comment-add-3.tcl->general_comments_new

Testcases:
general_comments_create_retrieve

general_comments_package_url (public)

 general_comments_package_url

Returns a URL pointing to the mounted general-comments package. Uses util_memoize for caching.

Partial Call Graph (max 5 caller/called nodes):
%3 test_general_comments_create_link general_comments_create_link (test general-comments) general_comments_package_url general_comments_package_url test_general_comments_create_link->general_comments_package_url site_node::get_package_url site_node::get_package_url (public) general_comments_package_url->site_node::get_package_url general_comments::create_link general_comments::create_link (public, deprecated) general_comments::create_link->general_comments_package_url general_comments::get_comments general_comments::get_comments (public, deprecated) general_comments::get_comments->general_comments_package_url general_comments_create_link general_comments_create_link (public) general_comments_create_link->general_comments_package_url general_comments_get_comments general_comments_get_comments (public) general_comments_get_comments->general_comments_package_url packages/general-comments/www/test.tcl packages/general-comments/ www/test.tcl packages/general-comments/www/test.tcl->general_comments_package_url

Testcases:
general_comments_create_link
[ hide source ] | [ make this the default ]

Content File Source

# /packages/general-comments/tcl/general-comments-procs.tcl

# Porting: Moved most queries from variables to in-line
# for the QueryExtractor, appended '_deprecated' to
# query-names in 'ad_proc -deprecated' functions.
# Left one duplicate with 100% identical SQL (pascal)

ad_library {
    Utility procs for general-comments

    @author Phong Nguyen <phong@arsdigita.com>
    @author Pascal Scheffers <pascal@scheffers.net>

    @creation-date 2000-10-12
    @cvs-id $Id: general-comments-procs.tcl,v 1.25.2.8 2023/02/07 12:46:43 antoniop Exp $
}


d_proc general_comments_new {
    -object_id:required
    -comment_id:required
    -title:required
    -comment_mime_type:required
    -context_id:required
    {-user_id ""}
    {-creation_ip ""}
    -is_live:required
    -category:required
    -content:required
} {
    Creates a comment and attaches it to a given object ID

    @return

    @error
} {

    # Generate a unique id for the message
    set rfc822_id [ns_uuid]

    db_transaction {

        db_exec_plsql insert_comment {}
        db_dml add_entry {}
        set revision_id [content::item::get_latest_revision \
                             -item_id $comment_id]
        db_dml set_content {} -blobs [list $content]

        # Grant the user sufficient permissions to
        # created comment. This is done here to ensure that
        # a fail on permissions granting will not leave
        # the comment with incorrect permissions.
        if {$user_id ne ""} {
            permission::grant -object_id $comment_id \
                -party_id $user_id \
                -privilege "read"

            permission::grant -object_id $comment_id \
                -party_id $user_id \
                -privilege "write"

        }
    }

    # Convert the comment to HTML
    if {$comment_mime_type ne "text/html"} {
        set content [ad_html_text_convert $content]
    }

    # Start notifications
    callback general_comments::notify_objects \
        -object_id $object_id \
        -comment $content \
        -title $title \
        -object_type [acs_object_type $object_id]

    return $revision_id
}

d_proc -public general_comments_delete_messages {
    -package_id:required
} {
    Deletes all comments belonging to specified package.
} {
    foreach comment_id [db_list get_comments {
        select comment_id
        from general_comments c,
             acs_objects o
        where c.comment_id = o.object_id
          and o.package_id = :package_id
    }] {
        content::item::delete -item_id $comment_id
    }
}

d_proc -public general_comments_get_comments {
    { -print_content_p:integer 0 }
    { -print_attachments_p:integer 0 }
    { -print_user_info_p:integer 1}
    { -context_id:integer,0..1 "" }
    { -my_comments_only_p:integer 0 }
    object_id
    {return_url {}}
} {
    Generates a line item list of comments for the object_id.

    @param print_content_p Pass in 1 to print out content of comments.
    @param print_attachments_p Pass in 1 to print out attachments of comments,
    only works if print_content_p is 1.
    @param context_id Show only comments with given context_id
    @param object_id The object_id to retrieve the comments for.
    @param return_url A url for the user to return to after viewing a comment.
} {
    # get the package url
    set package_url [general_comments_package_url]
    if { $package_url eq "" } {
        return ""
    }

    # package_id
    array set node_array [site_node::get -url $package_url]
    set package_id $node_array(package_id)

    # set ordering
    set recent_on_top_p [parameter::get \
                             -package_id $package_id \
                             -parameter "RecentOnTopP" \
                             -default f]

    set sort_dir [expr {[string is true $recent_on_top_p] ? "desc" : "asc"}]

    # filter output to only see present user?
    set allow_my_comments_only_p [parameter::get \
                                      -package_id $package_id \
                                      -parameter "AllowDisplayMyCommentsLinkP" \
                                      -default t]

    set user_id [expr {[string is true $my_comments_only_p] &&
                       [string is true $allow_my_comments_only_p] ? [ad_conn user_id] : ""}]

    db_multirow -local -extend {
        pretty_date
        pretty_date2
        author_url
        view_url
    } comments get_comments_new [subst {
             select o.object_id as comment_id,
                    r.title,
                    r.mime_type,
                    o.creation_user,
                    o.creation_user as author,
                    o.creation_date,
                    case when :print_content_p = 1
                       then r.content
                       else [expr {[db_driverkey ""] eq "oracle" ? "empty_blob()" : "''"}] end as content,
                    ar.title as attachment_title,
                    ar.mime_type as attachment_mime_type,
                    coalesce(ae.label, ai.name) as attachment_name,
                    ai.item_id as attachment_item_id,
                    case when exists (select 1 from images
                             where image_id = ai.item_id) then 't' else 'f' end as image_p,
                    ae.url as attachment_url
               from cr_revisions r,
                    acs_objects o
                    left join cr_items ai on (:print_content_p = 1 and
                                              :print_attachments_p = 1 and
                                              o.object_id = ai.parent_id)
                    left join cr_revisions ar on ai.live_revision = ar.revision_id
                    left join cr_extlinks ae on ai.item_id = ae.extlink_id
              where o.object_id in (select comment_id
                                      from general_comments
                                     where object_id = :object_id)
                and r.revision_id = (select live_revision
                                       from cr_items
                                      where item_id = o.object_id)
                and (:context_id is null or o.context_id = :context_id)
                and (:user_id is null or o.creation_user = :user_id)
              order by o.creation_date $sort_dir
    }] {
        set author [person::name -person_id $author]

        if {$content ne ""} {
            set content [template::util::richtext::get_property html_value [list $content $mime_type]]
        }

        set pretty_date [lc_time_fmt $creation_date %x]
        set pretty_date2 [lc_time_fmt $creation_date "%q %X"]

        set author_url [export_vars -base /shared/community-member {{user_id $creation_user}}]
        set view_url [export_vars -base ${package_url}view-comment {comment_id return_url}]

        if {$image_p} {
            set attachment_url [export_vars -base ${package_url}view-image {{image_id $attachment_item_id} return_url}]
        } elseif {$attachment_url eq ""} {
            set attachment_url [export_vars -base ${package_url}file-download {{item_id $attachment_item_id}}]
        }
    }

    set template [acs_package_root_dir "general-comments"]/lib/comments.adp
    set template [template::themed_template $template]
    set code [template::adp_compile -file $template]
    set html [template::adp_eval code]

    return $html
}

d_proc -public general_comments_create_link {
    -object_name
    { -link_text #general-comments.Add_comment# }
    -context_id
    { -category {} }
    { -link_attributes "" }
    object_id
    {return_url {}}
} {
    Generates an html link to add a comment to an object.

    @param object_id   The object to comment on.
    @param return_url  A url for the user to return to after viewing a comment.
    @param object_name The name of the object.
    @param link_text   The text to display for the link.
    @param context_id  The context_id for the comment.
    @param category    A category to associate comment to.
    @param link_attributes  Some additional parameters for the link. Could be used
    to set the link title and other things like that. Ex. -link_attributes
    <i>{ title="My link title" }</i>
} {
    # get the package url
    set package_url [general_comments_package_url]
    if { $package_url eq "" } {
        return ""
    }

    # initialize variables
    if { ![info exists object_name] } { set object_name [acs_object_name $object_id] }
    if { ![info exists context_id] } { set context_id $object_id }

    set html [subst {<a href="[ns_quotehtml [export_vars -base ${package_url}comment-add {object_id
         object_name return_url context_id category}]]" $link_attributes>$link_text</a>}]

    return $html
}

ad_proc -public general_comments_package_url {} {
    Returns a URL pointing to the mounted general-comments package.
    Uses util_memoize for caching.
} {
    return [site_node::get_package_url -package_key "general-comments"]
}

# these are being replaced with the above procs
namespace eval general_comments {

    ad_proc -deprecated get_comments {object_id return_url} {
        Generates a line item list of comments for the object_id.

        @param object_id The object_id to retrieve the comments for.
        @param return_url A url for the user to return to after viewing a comment.

        @see general_comments_get_comments
    } {

        # get the package url
        set package_url [general_comments_package_url]

        set html ""
        db_foreach get_comments_deprecated "
             select g.comment_id,
                    r.title,
                    r.content,
                    r.mime_type,
                    o.creation_user,
                    to_char(o.creation_date, 'MM-DD-YYYY') as creation_date,
                    p.first_names || ' ' || p.last_name as author
               from general_comments g,
                    cr_items i,
                    cr_revisions r,
                    acs_objects o,
                    persons p
              where g.object_id = :object_id and
                    i.item_id = g.comment_id and
                    r.revision_id = i.live_revision and
                    o.object_id = g.comment_id and
                    p.person_id = o.creation_user
              order by creation_date" {
                  append html [subst {
                      <li><a href="[ns_quotehtml [export_vars -base ${package_url}view-comment {comment_id return_url}]]">$title</a>
                      by $author$creation_date<br>
                  }]
              }
        return "$html"
    }

    ad_proc -deprecated create_link {object_id object_name return_url link_text {context_id ""} {category ""}} {
        Generates an html link to add a comment to an object.
        @param object_id   The object to comment on.
        @param object_name The name of the object.
        @param return_url  A url for the user to return to after viewing a comment.
        @param link_text   The text to display for the link.
        @param category    A category to associate comment to.

        @see general_comments_create_link
    } {
        # get the package url
        set package_url [general_comments_package_url]

        set html [subst {<a href="[ns_quotehtml [export_vars -base ${package_url}comment-add {object_id
             object_name return_url context_id category}]]">$link_text</a>
        }]
        return $html
    }

}

#
# Local variables:
#    mode: tcl
#    tcl-indent-level: 4
#    indent-tabs-mode: nil
# End: