ckfinder-procs.tcl

CKEditor 4 helper for ckfinder interface (not complete) This script defines the following public procs: ::richtext::ckeditor4::ckfinder::file_attach ::richtext::ckeditor4::ckfinder::return_file

Location:
packages/richtext-ckeditor4/tcl/ckfinder-procs.tcl
Created:
15 Aug 2017
Author:
Gustaf Neumann
CVS Identification:
$Id: ckfinder-procs.tcl,v 1.4.2.5 2022/02/26 13:23:47 gustafn Exp $ NOTE: the delivery of files performs two permission checks, once in the requestprocessor (the site nodes) and once for the concrete file. If one whishes to make uploaded files readable by "The Public", make sure that the /

Procedures in this file

Detailed information

richtext::ckeditor4::ckfinder::file_attach (public)

 richtext::ckeditor4::ckfinder::file_attach \
    [ -import_file import_file ] [ -mime_type mime_type ] \
    [ -object_id object_id ] [ -privilege privilege ] \
    [ -user_id user_id ] [ -peeraddr peeraddr ] \
    [ -package_id package_id ] [ -image ]

Insert the provided file to the content repository as a new item and attach it to the specified object_id via the attachment API. This makes sure that the file will be deleted from the content repository, when the provided object_id is deleted. The user must have at least "read" privileges on the object, but other stronger privileges can be supplied via parameter.

Switches:
-import_file (optional)
-mime_type (optional)
-object_id (optional)
-privilege (optional, defaults to "read")
-user_id (optional)
-peeraddr (optional)
-package_id (optional)
-image (optional, boolean)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/richtext-ckeditor4/tcl/ckfinder-init.tcl packages/richtext-ckeditor4/ tcl/ckfinder-init.tcl richtext::ckeditor4::ckfinder::file_attach richtext::ckeditor4::ckfinder::file_attach packages/richtext-ckeditor4/tcl/ckfinder-init.tcl->richtext::ckeditor4::ckfinder::file_attach attachments::attach attachments::attach (public) richtext::ckeditor4::ckfinder::file_attach->attachments::attach content::revision::new content::revision::new (public) richtext::ckeditor4::ckfinder::file_attach->content::revision::new permission::require_permission permission::require_permission (public) richtext::ckeditor4::ckfinder::file_attach->permission::require_permission richtext::ckeditor4::ckfinder::require_root_folder richtext::ckeditor4::ckfinder::require_root_folder (private) richtext::ckeditor4::ckfinder::file_attach->richtext::ckeditor4::ckfinder::require_root_folder

Testcases:
No testcase defined.

richtext::ckeditor4::ckfinder::query_page_contract (private)

 richtext::ckeditor4::ckfinder::query_page_contract [ -level level ] \
    params

Helper function similar to ad_page_contract, but works only on query variables.

Switches:
-level (optional, defaults to "1")
Parameters:
params (required)
Returns:
list of complaints, which is empty in case of success

Partial Call Graph (max 5 caller/called nodes):
%3 packages/richtext-ckeditor4/tcl/ckfinder-init.tcl packages/richtext-ckeditor4/ tcl/ckfinder-init.tcl richtext::ckeditor4::ckfinder::query_page_contract richtext::ckeditor4::ckfinder::query_page_contract packages/richtext-ckeditor4/tcl/ckfinder-init.tcl->richtext::ckeditor4::ckfinder::query_page_contract ad_complaints_get_list ad_complaints_get_list (public) richtext::ckeditor4::ckfinder::query_page_contract->ad_complaints_get_list ad_page_contract_filter_invoke ad_page_contract_filter_invoke (public) richtext::ckeditor4::ckfinder::query_page_contract->ad_page_contract_filter_invoke

Testcases:
No testcase defined.

richtext::ckeditor4::ckfinder::require_root_folder (private)

 richtext::ckeditor4::ckfinder::require_root_folder \
    [ -parent_id parent_id ] [ -name name ]

Helper function to find the root folder for ckfinder attachments.

Switches:
-parent_id (optional, defaults to "-100")
-name (optional, defaults to "attachments")

Partial Call Graph (max 5 caller/called nodes):
%3 richtext::ckeditor4::ckfinder::file_attach richtext::ckeditor4::ckfinder::file_attach (public) richtext::ckeditor4::ckfinder::require_root_folder richtext::ckeditor4::ckfinder::require_root_folder richtext::ckeditor4::ckfinder::file_attach->richtext::ckeditor4::ckfinder::require_root_folder content::item::get_id content::item::get_id (public) richtext::ckeditor4::ckfinder::require_root_folder->content::item::get_id content::item::new content::item::new (public) richtext::ckeditor4::ckfinder::require_root_folder->content::item::new

Testcases:
No testcase defined.

richtext::ckeditor4::ckfinder::return_file (public)

 richtext::ckeditor4::ckfinder::return_file \
    [ -revision_id revision_id ] [ -user_id user_id ]

Return the file with the specified revision_id to the user. The user must have at least "read" permissions to obtain the file.

Switches:
-revision_id (optional)
-user_id (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/richtext-ckeditor4/tcl/ckfinder-init.tcl packages/richtext-ckeditor4/ tcl/ckfinder-init.tcl richtext::ckeditor4::ckfinder::return_file richtext::ckeditor4::ckfinder::return_file packages/richtext-ckeditor4/tcl/ckfinder-init.tcl->richtext::ckeditor4::ckfinder::return_file ad_returnfile_background ad_returnfile_background (public) richtext::ckeditor4::ckfinder::return_file->ad_returnfile_background content::revision::get_cr_file_path content::revision::get_cr_file_path (public) richtext::ckeditor4::ckfinder::return_file->content::revision::get_cr_file_path db_string db_string (public) richtext::ckeditor4::ckfinder::return_file->db_string permission::require_permission permission::require_permission (public) richtext::ckeditor4::ckfinder::return_file->permission::require_permission

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

Content File Source

ad_library {

    CKEditor 4 helper for ckfinder interface (not complete)

    This script defines the following public procs:

       ::richtext::ckeditor4::ckfinder::file_attach
       ::richtext::ckeditor4::ckfinder::return_file

    @author Gustaf Neumann
    @creation-date 15 Aug 2017
    @cvs-id $Id: ckfinder-procs.tcl,v 1.4.2.5 2022/02/26 13:23:47 gustafn Exp $

    NOTE: the delivery of files performs two permission checks, once
    in the requestprocessor (the site nodes) and once for the concrete file.
    If one whishes to make uploaded files readable by "The Public", make
    sure that the /

}

namespace eval ::richtext::ckeditor4::ckfinder {

    d_proc -public file_attach {
        -import_file
        -mime_type
        -object_id
        {-privilege read}
        -user_id
        -peeraddr
        -package_id
        {-image:boolean}
    } {

        Insert the provided file to the content repository as a
        new item and attach it to the specified object_id via
        the attachment API. This makes sure that the file will be
        deleted from the content repository, when the provided
        object_id is deleted.

        The user must have at least "read" privileges on the object,
        but other stronger privileges can be supplied via parameter.

    } {
        permission::require_permission \
            -party_id $user_id \
            -object_id $object_id \
            -privilege $privilege

        if {$image_p} {
            #
            # Check if we can handle the mime type. Currently, only the
            # following four mime types are supported, since these are
            # supported by "ns_imgsize", which is used to determine the
            # dimensions of the image.
            #
            switch -- $mime_type {
                image/jpg -
                image/jpeg -
                image/gif -
                image/png {
                    set ext .[lindex [split $mime_type /] 1]
                    lassign [ns_imgsize $import_file] width height
                    set success 1
                }
                default {
                    ns_log warning "file_attach: can't handle image type '$mime_type'"
                    return [list \
                                success 0 \
                                errMsg "can't handle image type '$mime_type'"]
                }
            }
        } else {
            set width 0
            set height 0
            set success 1
        }
        #
        # Create a new item without child_rels
        #
        set name $object_id-[clock clicks -microseconds]
        set item_id [::acs::dc call content_item new \
                         -name            $name \
                         -parent_id       [require_root_folder] \
                         -context_id      $object_id \
                         -creation_user   $user_id \
                         -creation_ip     $peeraddr \
                         -item_subtype    "content_item" \
                         -storage_type    "file" \
                         -package_id      $package_id \
                         -with_child_rels f]

        #
        # Create a revision for the fresh content_item
        #
        set revision_id [xo::dc nextval acs_object_id_seq]
        content::revision::new \
            -revision_id     $revision_id \
            -item_id         $item_id \
            -title           $name \
            -is_live         t \
            -creation_user   $user_id \
            -creation_ip     $peeraddr \
            -content_type    "content_revision" \
            -package_id      $package_id \
            -tmp_filename    $import_file \
            -mime_type       $mime_type

        #
        # Attach the file to the object via the attachments API
        #
        attachments::attach \
            -object_id $object_id \
            -attachment_id $revision_id

        return [list \
                    success $success \
                    name $name \
                    file_id $revision_id \
                    width $width \
                    height $height \
                   ]
    }

    d_proc -public return_file {
        -revision_id
        -user_id
    } {

        Return the file with the specified revision_id to the
        user. The user must have at least "read" permissions to
        obtain the file.

    } {
ns_log notice =================================
        ns_log notice "permission::require_permission \
            -party_id $user_id \
            -object_id $revision_id \
            -privilege read"
        permission::require_permission \
            -party_id $user_id \
            -object_id $revision_id \
            -privilege read

        set file_path [content::revision::get_cr_file_path \
                           -revision_id $revision_id]
        set mime_type [db_string get_mime_type {
            select mime_type from cr_revisions where revision_id = :revision_id
        }]
        ad_returnfile_background 200 $mime_type $file_path
    }

    d_proc -private require_root_folder {
        {-parent_id -100}
        {-name attachments}
    } {

        Helper function to find the root folder for ckfinder
        attachments.

    } {
        set root_folder_id [content::item::get_id \
                                -root_folder_id $parent_id \
                                -item_path $name]
        if {$root_folder_id eq ""} {
            set root_folder_id [content::item::new \
                                    -name $name \
                                    -parent_id $parent_id]
        }
        return $root_folder_id
    }


    d_proc -private query_page_contract {
        {-level 1}
        params
    } {

        Helper function similar to ad_page_contract, but works only on
        query variables.

        @return list of complaints, which is empty in case of success

    } {
        #
        # Process params provided by the query
        #
        foreach {key value} [ns_set array [ns_parsequery [ns_conn query]]] {
            set param($key$value
        }
        #ns_log notice "provided params [array get param]"
        #
        # Process params as specified in the page contract
        #
        foreach p $params {
            lassign $p spec default
            lassign [split $spec :] name filters
            #ns_log notice "param $name exists [info exists param($name)]"
            if {[info exists param($name)]} {
                set value $param($name)
                #
                # Call every page contract filter for this
                # parameter. On failures, complaints are added to a
                # global variable which is picked-up later.
                #
                foreach filter [split $filters ,] {
                    ad_page_contract_filter_invoke $filter $name value
                }
            } else {
                set param($name$default
            }
            uplevel $level [list set $name $param($name)]
        }
        if {[info exists ::ad_page_contract_complaints]} {
            set complaints [ad_complaints_get_list]
        } else {
            set complaints ""
        }
        return $complaints
    }

}

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