quick search:

ZClip! like functionality

Submitted by: runyaga
Last Edited: 2001-07-09

Category: CMF

Average rating is: 4.33 out of 5 (3 ratings)

want to have a javascript hyperlink that bookmarks the current page i'm looking at into my CMF folder. will create a Folder in the Members directory called MyBookmarks and add the current page.

Source (Text):
userName = context.REQUEST.AUTHENTICATED_USER.getUserName()
linkFolder = 'MyBookmarks'
newLink = None
userFolder = None

if userName=='Anonymous':
    return 'go away'

#lets make sure we have a place to store the Links
if hasattr(context.Members, userName):
    userFolder=getattr(context.Members, userName)
    if hasattr(userFolder, linkFolder):
        linkFolder=getattr(userFolder, linkFolder)
        newFolder=userFolder.invokeFactory('Folder', linkFolder)
        if hasattr(userFolder, linkFolder):
            linkFolder=getattr(userFolder, linkFolder)
            return 'couldnt get the folder I created?, use the source Luke'
    return context.REQUEST.RESPONSE.redirect('login_form')

#now we for sure have the linkFolder
linkFolder.invokeFactory(type_name, id)

if hasattr(linkFolder, id):
    newLink = getattr(linkFolder, id)
    return str(id)+' not found in runyaga.myBookmarks'

#if reviewer, auto publish else put in review mode
if 'Reviewer' in context.REQUEST.AUTHENTICATED_USER.getRoles():
    context.portal_workflow.doActionFor(newLink, 'publish')
    context.portal_workflow.doActionFor(newLink, 'submit')

closeWindowHTML = '''<html><head><body onLoad="javascript:parent.close()"></body></head></html>;'''
return closeWindowHTML

drag this link to your Links bar in I.E.
<a href="javascript:function stripIllegals(url) {var retVal = '';for (x=0;x<url.length;x++){if ( (url.charCodeAt(x) >=97 && url.charCodeAt(x) <=122) ||(url.charCodeAt(x) >=62 && url.charCodeAt(x) <=90) ) {retVal+=url.charAt(x);}}return retVal;}Q='';if(top.frames.length==0)Q=this.document.selection.createRange().text;void(btw=window.open('http://yoursite.com/Members/createZClip?type_name=Link&body_stx='+escape(Q)+'&remote_url='+escape(location.href)+'&title='+escape(this.document.title)+'&id='+stripIllegals(escape(this.document.title)),'zURLform','scrollbars=no,width=485,height=315,left=75,top=175,status=yes'));btw.focus();">ZClip! hook</a>

inspired by the ZClip! ZClass product this does the same thing, but it does not prompt you
with a window to customize your ZClip! (Link object in CMF) - it just creates it.

* checks to make sure your not anonymous, if
* gets the users /Members/user folder and checks to see if they
have a folder called linkFolderm if not it creates one.
* if they dont have a /Members/user folder it tries to Log them in.
* creates a new Link object and populates
* if your a reviewer - publish, else submit to review
* display a window that closes ;)


No Comments