email_image::new_item (public)

 email_image::new_item -user_id user_id [ -return_url return_url ] \
    [ -bgcolor bgcolor ] [ -transparent transparent ]

Defined in packages/acs-subsite/tcl/email-image-procs.tcl

Creates the email_image of the user with his/her email on it and store it in the content repository under the Email_Images folder.

Switches:
-user_id (required)
-return_url (optional)
-bgcolor (optional)
The background color of the image in the format \#xxxxxx, default to \#ffffff
-transparent (optional)
If you want the background color transparent set it to 1. Default to 1

Partial Call Graph (max 5 caller/called nodes):
%3 email_image::get_user_email email_image::get_user_email (public) email_image::new_item email_image::new_item email_image::get_user_email->email_image::new_item ad_conn ad_conn (public) email_image::new_item->ad_conn ad_tmpdir ad_tmpdir (public) email_image::new_item->ad_tmpdir content::item::new content::item::new (public) email_image::new_item->content::item::new content::revision::new content::revision::new (public) email_image::new_item->content::revision::new cr_filename_to_mime_type cr_filename_to_mime_type (public) email_image::new_item->cr_filename_to_mime_type

Testcases:
No testcase defined.
Source code:

    # First we create a type and a folder in the content repository
    # with label Email_Images where only items of type email_image
    # will be stored.

    set font_size 14
    set font_type helvetica
    set folder_id [email_image::get_folder_id]
    set email [email_image::get_email -user_id $user_id]
    set image_name "email${user_id}.gif"
    set email_length [string length $email]
    set dest_path "[ad_tmpdir]/$image_name"
    set width [expr {($email_length * ($font_size / 2)) + 2}]
    set height $font_size
    set ypos [expr { ($height / 2) + 3 }]
    set size "${width}x$height"

    if {$bgcolor eq ""} {
        set bgcolor "\#ffffff"
    }

    set bg "xc:$bgcolor"

    # Creating an image of the right length where the email will be
    if {[catch {exec [::util::which convert] -size $size $bg $dest_path} errmsg]} {
        return ""
    }

    # Creating the image with the email of the user on it
    if {[catch {exec [::util::which convert] -font $font_type -fill blue -pointsize $font_size -draw "text 0,$ypos $email"  $dest_path $dest_path} errmsg]} {
        return ""
    }

    if { $transparent eq "" || $transparent eq "1" } {
        # Making the bg color transparent
        if {[catch {exec [::util::which convert] $dest_path -transparent $bgcolor $dest_path} errmsg]} {
            return ""
        }
    }

    # Time to store the image in the content repository
    db_transaction {

        set mime_type [cr_filename_to_mime_type -create $dest_path]
        set creation_ip [ad_conn peeraddr]

        set item_id [content::item::new  -name $image_name  -parent_id $folder_id  -content_type "email_image"  -creation_ip $creation_ip]

        set revision_id [content::revision::new  -item_id $item_id  -title $image_name  -mime_type $mime_type   -description "User email image"  -creation_ip $creation_ip  -tmp_filename $dest_path  -is_live t]

        email_image::add_relation -user_id $user_id -item_id $item_id
        #content::item::set_live_revision -revision_id $revision_id
        # db_dml new_lob_content {} -blob_files [list ${dest_path}]
        # db_dml lob_size {}
    }

    # Delete the temporary file created by ImageMagick
    catch { file delete -- $dest_path } errMsg

    set img_src [ns_quotehtml "/shared/email-image-bits.tcl?user_id=$user_id&revision_id=$revision_id"]
    set send_email_url [ns_quotehtml "/shared/send-email?sendto=$user_id&return_url=$return_url"]
    set email_image [subst {<a href="$send_email_url"><img style="border:0" src="$img_src" alt="#acs-subsite.Email#"></a>}]

    return "$email_image"
Generic XQL file:
packages/acs-subsite/tcl/email-image-procs.xql

PostgreSQL XQL file:
packages/acs-subsite/tcl/email-image-procs-postgresql.xql

Oracle XQL file:
packages/acs-subsite/tcl/email-image-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: