bookmarks-procs.tcl

TCL library for the bookmarks module. Credit for the ACS 3 version of this module goes to:

Location:
packages/bookmarks/tcl/bookmarks-procs.tcl
Created:
December 2000
Authors:
David Hill <dh@arsdigita.com>
Aurelius Prochazka (aure@arsdigita.com) The upgrade of this module to ACS 4 was done by
Peter Marklund <pmarklun@arsdigita.com>
Ken Kennedy (kenzoid@io.com) in December 2000.
CVS Identification:
$Id: bookmarks-procs.tcl,v 1.9 2014/04/18 06:49:49 gustafn Exp $

Procedures in this file

Detailed information

bm_bookmark_private_p (public)

 bm_bookmark_private_p bookmark_id
Parameters:
bookmark_id (required)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/bookmarks/www/bookmark-edit.tcl packages/bookmarks/ www/bookmark-edit.tcl bm_bookmark_private_p bm_bookmark_private_p packages/bookmarks/www/bookmark-edit.tcl->bm_bookmark_private_p packages/bookmarks/www/bookmark-permissions.tcl packages/bookmarks/ www/bookmark-permissions.tcl packages/bookmarks/www/bookmark-permissions.tcl->bm_bookmark_private_p db_string db_string (public) bm_bookmark_private_p->db_string

Testcases:
No testcase defined.

bm_close_js_brackets (private)

 bm_close_js_brackets prev_folder_p prev_lev lev

This helper function is used by the tree-dynamic.tcl page in constructing the bookmark tree for the javascript page.

Parameters:
prev_folder_p (required)
prev_lev (required)
lev (required)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/bookmarks/www/tree-dynamic.tcl packages/bookmarks/ www/tree-dynamic.tcl bm_close_js_brackets bm_close_js_brackets packages/bookmarks/www/tree-dynamic.tcl->bm_close_js_brackets

Testcases:
No testcase defined.

bm_context_bar_args (public)

 bm_context_bar_args arg_list viewed_user_id

If viewed_user_id <> browsing_user_id we need to prefix the context bar args with an entry for bookmarks of the viewed user. If the arg_list is empty it is assumed that we are on the index page and that otherwise the page has been linked from the index page.

Parameters:
arg_list (required)
viewed_user_id (required)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/bookmarks/www/bookmark-add-import.tcl packages/bookmarks/ www/bookmark-add-import.tcl bm_context_bar_args bm_context_bar_args packages/bookmarks/www/bookmark-add-import.tcl->bm_context_bar_args packages/bookmarks/www/bookmark-add-one.tcl packages/bookmarks/ www/bookmark-add-one.tcl packages/bookmarks/www/bookmark-add-one.tcl->bm_context_bar_args packages/bookmarks/www/bookmark-edit.tcl packages/bookmarks/ www/bookmark-edit.tcl packages/bookmarks/www/bookmark-edit.tcl->bm_context_bar_args packages/bookmarks/www/bookmark-permissions.tcl packages/bookmarks/ www/bookmark-permissions.tcl packages/bookmarks/www/bookmark-permissions.tcl->bm_context_bar_args packages/bookmarks/www/bookmarks-check.tcl packages/bookmarks/ www/bookmarks-check.tcl packages/bookmarks/www/bookmarks-check.tcl->bm_context_bar_args ad_conn ad_conn (public) bm_context_bar_args->ad_conn db_string db_string (public) bm_context_bar_args->db_string

Testcases:
No testcase defined.

bm_delete_permission_p (public)

 bm_delete_permission_p bookmark_id

Returns boolean value indicating if the browsing user may delete the bookmark.

Parameters:
bookmark_id (required)

Partial Call Graph (max 5 caller/called nodes):
%3 bm_require_delete_permission bm_require_delete_permission (public) bm_delete_permission_p bm_delete_permission_p bm_require_delete_permission->bm_delete_permission_p packages/bookmarks/www/bookmark-edit.tcl packages/bookmarks/ www/bookmark-edit.tcl packages/bookmarks/www/bookmark-edit.tcl->bm_delete_permission_p ad_conn ad_conn (public) bm_delete_permission_p->ad_conn ad_decode ad_decode (public) bm_delete_permission_p->ad_decode db_string db_string (public) bm_delete_permission_p->db_string

Testcases:
No testcase defined.

bm_folder_selection (public)

 bm_folder_selection user_id bookmark_id folder_p

This procedure is used to present a list of available folders to put bookmark or folder in.

Parameters:
user_id (required)
bookmark_id (required)
folder_p (required)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/bookmarks/www/folder-selection.tcl packages/bookmarks/ www/folder-selection.tcl bm_folder_selection bm_folder_selection packages/bookmarks/www/folder-selection.tcl->bm_folder_selection ad_conn ad_conn (public) bm_folder_selection->ad_conn db_map db_map (public) bm_folder_selection->db_map db_multirow db_multirow (public) bm_folder_selection->db_multirow

Testcases:
No testcase defined.

bm_get_html_description (public)

 bm_get_html_description html_code
Parameters:
html_code (required)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/bookmarks/www/bookmark-add-one.tcl packages/bookmarks/ www/bookmark-add-one.tcl bm_get_html_description bm_get_html_description packages/bookmarks/www/bookmark-add-one.tcl->bm_get_html_description packages/bookmarks/www/bookmarks-check.tcl packages/bookmarks/ www/bookmarks-check.tcl packages/bookmarks/www/bookmarks-check.tcl->bm_get_html_description parameter::get parameter::get (public) bm_get_html_description->parameter::get

Testcases:
No testcase defined.

bm_get_html_keywords (public)

 bm_get_html_keywords html_code
Parameters:
html_code (required)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/bookmarks/www/bookmark-add-one.tcl packages/bookmarks/ www/bookmark-add-one.tcl bm_get_html_keywords bm_get_html_keywords packages/bookmarks/www/bookmark-add-one.tcl->bm_get_html_keywords packages/bookmarks/www/bookmarks-check.tcl packages/bookmarks/ www/bookmarks-check.tcl packages/bookmarks/www/bookmarks-check.tcl->bm_get_html_keywords parameter::get parameter::get (public) bm_get_html_keywords->parameter::get

Testcases:
No testcase defined.

bm_get_html_title (public)

 bm_get_html_title html_code
Parameters:
html_code (required)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/bookmarks/www/bookmark-add-one.tcl packages/bookmarks/ www/bookmark-add-one.tcl bm_get_html_title bm_get_html_title packages/bookmarks/www/bookmark-add-one.tcl->bm_get_html_title packages/bookmarks/www/bookmarks-check.tcl packages/bookmarks/ www/bookmarks-check.tcl packages/bookmarks/www/bookmarks-check.tcl->bm_get_html_title parameter::get parameter::get (public) bm_get_html_title->parameter::get

Testcases:
No testcase defined.

bm_get_root_folder_id (public)

 bm_get_root_folder_id package_id user_id

Returns the id of the bookmark root folder of a user in a package instance. This root folder is used for default access permissioning of a users bookmarks (bookmarks will inherit permissions).

Parameters:
package_id (required)
user_id (required)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/bookmarks/www/bookmark-header.tcl packages/bookmarks/ www/bookmark-header.tcl bm_get_root_folder_id bm_get_root_folder_id packages/bookmarks/www/bookmark-header.tcl->bm_get_root_folder_id packages/bookmarks/www/bookmark-permissions.tcl packages/bookmarks/ www/bookmark-permissions.tcl packages/bookmarks/www/bookmark-permissions.tcl->bm_get_root_folder_id packages/bookmarks/www/bookmarks-check.tcl packages/bookmarks/ www/bookmarks-check.tcl packages/bookmarks/www/bookmarks-check.tcl->bm_get_root_folder_id packages/bookmarks/www/bookmarks-import.tcl packages/bookmarks/ www/bookmarks-import.tcl packages/bookmarks/www/bookmarks-import.tcl->bm_get_root_folder_id packages/bookmarks/www/delete-dead-links.tcl packages/bookmarks/ www/delete-dead-links.tcl packages/bookmarks/www/delete-dead-links.tcl->bm_get_root_folder_id db_exec_plsql db_exec_plsql (public) bm_get_root_folder_id->db_exec_plsql

Testcases:
No testcase defined.

bm_handle_bookmark_double_click (public)

 bm_handle_bookmark_double_click bookmark_id errmsg return_url
Parameters:
bookmark_id (required)
errmsg (required)
return_url (required)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/bookmarks/www/bookmark-add-one-2.tcl packages/bookmarks/ www/bookmark-add-one-2.tcl bm_handle_bookmark_double_click bm_handle_bookmark_double_click packages/bookmarks/www/bookmark-add-one-2.tcl->bm_handle_bookmark_double_click packages/bookmarks/www/folder-add-2.tcl packages/bookmarks/ www/folder-add-2.tcl packages/bookmarks/www/folder-add-2.tcl->bm_handle_bookmark_double_click ad_return_template ad_return_template (public) bm_handle_bookmark_double_click->ad_return_template ad_returnredirect ad_returnredirect (public) bm_handle_bookmark_double_click->ad_returnredirect ad_script_abort ad_script_abort (public) bm_handle_bookmark_double_click->ad_script_abort db_string db_string (public) bm_handle_bookmark_double_click->db_string template::adp_level template::adp_level (public) bm_handle_bookmark_double_click->template::adp_level

Testcases:
No testcase defined.

bm_host_url (public)

 bm_host_url complete_url

Takes a URL and returns the host portion of it (i.e., http://hostname.com/), which always contains a trailing slash. Returns empty string if complete_url wasn't parseable.

Parameters:
complete_url (required)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/bookmarks/www/bookmark-add-one-2.tcl packages/bookmarks/ www/bookmark-add-one-2.tcl bm_host_url bm_host_url packages/bookmarks/www/bookmark-add-one-2.tcl->bm_host_url packages/bookmarks/www/bookmark-edit-2.tcl packages/bookmarks/ www/bookmark-edit-2.tcl packages/bookmarks/www/bookmark-edit-2.tcl->bm_host_url packages/bookmarks/www/bookmarks-import.tcl packages/bookmarks/ www/bookmarks-import.tcl packages/bookmarks/www/bookmarks-import.tcl->bm_host_url

Testcases:
No testcase defined.

bm_initialize_in_closed_p (public)

 bm_initialize_in_closed_p viewed_user_id in_closed_p_id package_id
Parameters:
viewed_user_id (required)
in_closed_p_id (required)
package_id (required)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/bookmarks/www/index.tcl packages/bookmarks/ www/index.tcl bm_initialize_in_closed_p bm_initialize_in_closed_p packages/bookmarks/www/index.tcl->bm_initialize_in_closed_p db_exec_plsql db_exec_plsql (public) bm_initialize_in_closed_p->db_exec_plsql

Testcases:
No testcase defined.

bm_repeat_string (public)

 bm_repeat_string string iteration_number
Parameters:
string (required)
iteration_number (required)

Partial Call Graph (max 5 caller/called nodes):
%3

Testcases:
No testcase defined.

bm_require_delete_permission (public)

 bm_require_delete_permission bookmark_id

This proc verifyes that the user may delete the bookmark/folder and all its contained bookmarks/folders.

Parameters:
bookmark_id (required)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/bookmarks/www/bookmark-delete-2.tcl packages/bookmarks/ www/bookmark-delete-2.tcl bm_require_delete_permission bm_require_delete_permission packages/bookmarks/www/bookmark-delete-2.tcl->bm_require_delete_permission packages/bookmarks/www/bookmark-delete.tcl packages/bookmarks/ www/bookmark-delete.tcl packages/bookmarks/www/bookmark-delete.tcl->bm_require_delete_permission ad_return_template ad_return_template (public) bm_require_delete_permission->ad_return_template bm_delete_permission_p bm_delete_permission_p (public) bm_require_delete_permission->bm_delete_permission_p

Testcases:
No testcase defined.

bm_update_bookmark_private_p (public)

 bm_update_bookmark_private_p bookmark_id private_p
Parameters:
bookmark_id (required)
private_p (required)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/bookmarks/www/bookmark-edit-2.tcl packages/bookmarks/ www/bookmark-edit-2.tcl bm_update_bookmark_private_p bm_update_bookmark_private_p packages/bookmarks/www/bookmark-edit-2.tcl->bm_update_bookmark_private_p packages/bookmarks/www/bookmark-permissions-2.tcl packages/bookmarks/ www/bookmark-permissions-2.tcl packages/bookmarks/www/bookmark-permissions-2.tcl->bm_update_bookmark_private_p db_exec_plsql db_exec_plsql (public) bm_update_bookmark_private_p->db_exec_plsql

Testcases:
No testcase defined.

bm_user_can_write_in_some_folder_p (public)

 bm_user_can_write_in_some_folder_p viewed_user_id

Returns "t" if there is a folder that the browsing user can write in, and "f' otherwise.

Parameters:
viewed_user_id (required)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/bookmarks/www/bookmark-header.tcl packages/bookmarks/ www/bookmark-header.tcl bm_user_can_write_in_some_folder_p bm_user_can_write_in_some_folder_p packages/bookmarks/www/bookmark-header.tcl->bm_user_can_write_in_some_folder_p packages/bookmarks/www/index.tcl packages/bookmarks/ www/index.tcl packages/bookmarks/www/index.tcl->bm_user_can_write_in_some_folder_p ad_conn ad_conn (public) bm_user_can_write_in_some_folder_p->ad_conn ad_decode ad_decode (public) bm_user_can_write_in_some_folder_p->ad_decode db_string db_string (public) bm_user_can_write_in_some_folder_p->db_string

Testcases:
No testcase defined.
[ hide source ] | [ make this the default ]

Content File Source

ad_library {
    TCL library for the bookmarks module.

    Credit for the ACS 3 version of this module goes to:
    @author David Hill (dh@arsdigita.com)
    @author Aurelius Prochazka (aure@arsdigita.com)
  
    The upgrade of this module to ACS 4 was done by
    @author Peter Marklund (pmarklun@arsdigita.com)
    @author Ken Kennedy (kenzoid@io.com)
    in December 2000.

    @creation-date December 2000
    @cvs-id $Id: bookmarks-procs.tcl,v 1.9 2014/04/18 06:49:49 gustafn Exp $
}


ad_proc bm_folder_selection { user_id bookmark_id folder_p } {
    This procedure is used to present a list of available folders to 
    put bookmark or folder in.
} {
    # We cannot move folders to be their own children
    if { $folder_p == "t" } {
    set exclude_folders [db_map exclude_folders]
    } else {
    set exclude_folders ""
    }

    set package_id [ad_conn package_id]

    db_multirow folders folder_select "
    select /*+INDEX(bm_bookmarks bm_bookmarks_local_title_idx)*/ bookmark_id, 
    local_title,
    level as indentation
    from   bm_bookmarks
    where folder_p = 't'
    and owner_id = :user_id
    and bookmark_id <> :bookmark_id
    and parent_id <> :package_id
    and acs_permission.permission_p(bookmark_id, :user_id, 'write') = 't'
    $exclude_folders
    start with parent_id = :package_id
    connect by prior bookmark_id = parent_id
    " 
}


ad_proc bm_host_url {complete_url} {

    Takes a URL and returns the host portion of it (i.e.,
    http://hostname.com/), which always contains a trailing
    slash. Returns empty string if complete_url wasn't parseable.

} {
    if { [regexp {([^:\"]+://[^/]+)} $complete_url host_url] } {
    return "$host_url/"
    } else {
    return ""
    }
}


ad_proc bm_handle_bookmark_double_click { bookmark_id errmsg return_url } {
} {
    # check and see if this was a double click
    set dbclick_p [db_string dbclick "select count(*) 
                                          from   bm_bookmarks 
                                      where  bookmark_id = :bookmark_id"]
    
    if {$dbclick_p == 1} {   
        ad_returnredirect  -allow_complete_url $return_url
            ad_script_abort
    } else {

        upvar \#[template::adp_level] n_errors n_errors
        upvar \#[template::adp_level] error_list error_list

        set n_errors 1
        set error_list [list "There was an error making this insert into the database. $errmsg"]

          uplevel \#[template::adp_level] {
          ad_return_template "complaint"
          }
            ad_script_abort
    }
}


ad_proc bm_repeat_string { string iteration_number } {
} {
    if { $iteration_number <= 0} {
    return ""
    } 

    set return_string ""
    for { set i 0 } { $i < $iteration_number } { incr i } {
    append return_string $string
    }

    return $return_string
}


ad_proc bm_get_root_folder_id { package_id user_id } {
      Returns the id of the bookmark root folder of a user in a package
      instance. This root folder is used for default access permissioning 
      of a users bookmarks (bookmarks will inherit permissions).
} {
      set root_folder_id [db_exec_plsql fs_root_folder "
      begin
          :1 := bookmark.get_root_folder(
                package_id => :package_id,
                user_id    => :user_id);
      end;"]

      return $root_folder_id
}


ad_proc bm_user_can_write_in_some_folder_p { viewed_user_id } {
    Returns "t" if there is a folder that the browsing user can write
    in, and "f' otherwise.
} {
    set browsing_user_id [ad_conn user_id]

    set n_of_write_folders [db_string write_in_folders "select count(*) from bm_bookmarks
                     where owner_id = :viewed_user_id
                     and folder_p = 't'
                     and acs_permission.permission_p(bookmark_id, :browsing_user_id, 'write') = 't'"]

    return [ad_decode $n_of_write_folders "0" "f" "t"]
}


ad_proc bm_delete_permission_p { bookmark_id } {
    Returns boolean value indicating if the browsing user may delete
    the bookmark.
} {
    set browsing_user_id [ad_conn user_id]

    return [ad_decode [db_string delete_permission_p "select count(*) from bm_bookmarks 
    where acs_permission.permission_p(bookmark_id, :browsing_user_id, 'delete') = 'f'
    start with bookmark_id = :bookmark_id
    connect by prior bookmark_id = parent_id""0" "t" "f"]


}


ad_proc bm_require_delete_permission { bookmark_id } {
    This proc verifyes that the user may delete the bookmark/folder and all its
    contained bookmarks/folders.

} {
    if {[bm_delete_permission_p $bookmark_id] == "f"} {
    set n_errors 1
    set error_list [list "You either do not have delete permissions on this bookmark/folder, or you are trying to delete a folder that contains at least one bookmarks or folder that you may not delete"]
    ad_return_template "complaint"
    return -code return
    }
}


ad_proc bm_context_bar_args { arg_list viewed_user_id } {
    If viewed_user_id <> browsing_user_id we need to prefix the 
    context bar args with an entry for bookmarks of the viewed user. If the
    arg_list is empty it is assumed that we are on the index page and that otherwise
    the page has been linked from the index page.
} {
    set browsing_user_id [ad_conn user_id]
    
    if { $browsing_user_id ne $viewed_user_id && $viewed_user_id ne ""} {
    # The user is viewing someone elses bookmarks
    # and we need the set the context bar so that 
    # he can go back to viewing his own bookmarks
    set user_name [db_string user_name "select first_names || ' ' || last_name from cc_users where object_id = :viewed_user_id" -default ""]

    if { $arg_list eq "" } {
        # We are on the index page
        return [list "Bookmarks of $user_name"]
    } else {
        # We were linked from the index page
        return [linsert $arg_list 0 [list "index?viewed_user_id=$viewed_user_id" "Bookmarks of $user_name"]]
    }
    } else {
    return $arg_list
    }
}


ad_proc bm_get_html_title { html_code } {

} {
    set title ""
    regexp -nocase {<title>([^<]*)</title>} $html_code match title

    if {[string length $title]> [parameter::get -parameter URLTitleMaxLength] || [string length $title] > 499 } {
    set title "[string range $title 0 496]..."
    }

    return [string trim $title]
}


ad_proc bm_get_html_description { html_code } {

} {
    set description ""
    regexp -nocase {<meta name="description" content="([^"]*)"} $html_code match description

    if {[string length $description]> [parameter::get -parameter URLDescriptionMaxLength] || [string length $description] > 3999 } {
    set description "[string range $description 0 3996]..."
    }

    return [string trim $description]
}

ad_proc bm_get_html_keywords { html_code } {

} {
    set keywords ""
    regexp -nocase {<meta name="keywords" content="([^"]*)">} $html_code match keywords

    if {[string length $keywords]> [parameter::get -parameter URLKeywordsMaxLength] || [string length $keywords] > 3999 } {
    set keywords "[string range $keywords 0 3996]..."
    }

    return [string trim $keywords]
}


ad_proc bm_bookmark_private_p { bookmark_id } {

} {
    return [db_string bookmark_private_p "select bookmark.private_p(:bookmark_id) from dual"] 
}


ad_proc bm_update_bookmark_private_p { bookmark_id private_p} {

} {
    db_exec_plsql update_private_p {
        begin
           bookmark.update_private_p(:bookmark_id, :private_p);
        end;
    }
}


ad_proc bm_initialize_in_closed_p { viewed_user_id in_closed_p_id package_id} {

} {
    db_exec_plsql initialize_in_closed_p {
        begin
           bookmark.initialize_in_closed_p(:viewed_user_id, :in_closed_p_id, :package_id);
        end;
    }    
}

ad_proc -private bm_close_js_brackets {prev_folder_p prev_lev lev} {
	This helper function is used by the tree-dynamic.tcl page in
	constructing the bookmark tree for the javascript page.
} {
    set result ""
    if {$prev_folder_p && ($prev_lev >= $lev)} {
        # Empty folder. We need to add a fake bookmark to the folder or else
        # it will not have a folder icon attached to it.
        set i_str [string repeat "\t" $prev_lev]
        append result "$i_str\t\['Empty folder']\n"
        append result "$i_str],\n"
    }
    while {$prev_lev > $lev} {
        set i_str [string repeat "\t" [expr {$prev_lev - 1}]]
        append result "$i_str],\n"
        incr prev_lev -1
    }

    return $result
}