'Render resource-related CMS contents
@param module: the module prefix
@param resource: the resource name (without prefix)
@param record: the record ID (optional)
@param widget_id: the DOM node ID for the CMS widget
@param hide_if_empty: return an empty string when there is no
contents rather than a blank DIV'

@staticmethod
def resource_content(module, resource, record=None, widget_id=None, hide_if_empty=False):

    db = current.db
    table = current.s3db.cms_post
    ltable = db.cms_post_module
    query = (((((ltable.module == module) & (ltable.resource == resource)) & (ltable.record == record)) & (ltable.post_id == table.id)) & (table.deleted != True))
    _item = db(query).select(table.id, table.body, limitby=(0, 1)).first()
    auth = current.auth
    ADMIN = auth.get_system_roles().ADMIN
    ADMIN = auth.s3_has_role(ADMIN)
    if ADMIN:
        if (current.response.s3.crud.formstyle == 'bootstrap'):
            _class = 'btn'
        else:
            _class = 'action-btn'
        url_vars = {'module': module, 'resource': resource}
        if record:
            url_vars['record'] = record
        if _item:
            item = DIV(XML(_item.body), A(current.T('Edit'), _href=URL(c='cms', f='post', args=[_item.id, 'update'], vars=url_vars), _class=('%s    cms-edit' % _class)))
        else:
            item = A(current.T('Edit'), _href=URL(c='cms', f='post', args='create', vars=url_vars), _class=('%s    cms-edit' % _class))
    elif _item:
        item = XML(_item.body)
    else:
        item = ''
    if ((item != '') or (not hide_if_empty)):
        output = DIV(item, _id=widget_id, _class='cms_content')
    else:
        output = item
    return output
