#Parameters : entry_id,title,body,image_path

# Add object
new_id = context.invokeFactory(id=entry_id,type_name='COREBlogEntry')
ent = context[entry_id]

# Set body,title
ent.setContentType('text/plain','body')
ent.setTitle(title)
ent.setBody(body)

# Set category
cat_id = context.getCategoryFolder()['moblog'].getInternal_id()
ent.setEntry_categories(str(cat_id))

if not image_path == '':

    image_path = image_path.split(',')

    for x in image_path:
        # Add image reference
        ref_obj = context.restrictedTraverse(x)
        ent.addReference(ref_obj,'relatesTo')
        
    # Set position,size
    if len(image_path) == 1:
        ent.setMedia_position(3)
        ent.setMedia_size('preview')
    else:
        ent.setMedia_position(2)
        ent.setMedia_size('preview')
            
# Index entry
ent.indexObject()

# Publish entry
ent.content_status_modify(workflow_action='publish')
                                                     
