email_image::edit_email_image (public)

 email_image::edit_email_image -user_id user_id -new_email new_email \
    [ -bgcolor bgcolor ] [ -transparent transparent ]

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

Creates a new email_image of the user with his/her new edited email on it and store it in the content repository under the Email_Images folder. If the user has an image already stored it makes a new revision of the image, if not, it creates a new item with the new image.

Switches:
-user_id (required)
-new_email (required)
-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 packages/acs-subsite/lib/user-info.tcl packages/acs-subsite/ lib/user-info.tcl email_image::edit_email_image email_image::edit_email_image packages/acs-subsite/lib/user-info.tcl->email_image::edit_email_image ad_conn ad_conn (public) email_image::edit_email_image->ad_conn ad_tmpdir ad_tmpdir (public) email_image::edit_email_image->ad_tmpdir content::item::new content::item::new (public) email_image::edit_email_image->content::item::new content::revision::new content::revision::new (public) email_image::edit_email_image->content::revision::new cr_filename_to_mime_type cr_filename_to_mime_type (public) email_image::edit_email_image->cr_filename_to_mime_type

Testcases:
No testcase defined.
Source code:
    if { $new_email == [email_image::get_email -user_id $user_id] } {
        # Email didn't change
        return
    }
    set font_size 14
    set font_type helvetica
    set folder_id [email_image::get_folder_id]
    set image_name "email${user_id}.gif"
    set email_length [string length $new_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 } ] } {
        # ImageMagick not present
        return
    }

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

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

    set email_image_id [email_image::get_related_item_id -user_id $user_id]
    set mime_type [cr_filename_to_mime_type -create $dest_path]
    set creation_ip [ad_conn peeraddr]

    if { $email_image_id != "-1" } {
        db_transaction {
            set item_id $email_image_id
            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  -is_live t  -tmp_filename $dest_path]
            #content::item::set_live_revision -revision_id $revision_id
        }
    } else {
        db_transaction {

            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  -is_live t  -tmp_filename $dest_path]

            email_image::add_relation -user_id $user_id -item_id $item_id

#            db_dml update_cr_items {
#                update cr_items
#                set live_revision  = :revision_id
#                where item_id = :item_id                
#            }
#            #db_dml lob_content {} -blob_files [list ${dest_path}]
#            #db_dml lob_size {}
        }
    }
    # Delete the temporary file created by ImageMagick
    catch { file delete -- $dest_path } errMsg
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: