cancel
Showing results for 
Search instead for 
Did you mean: 

flaky WebPreviewer when used in anything outside of Share

ofrxnz
Champ in-the-making
Champ in-the-making
So, to give everyone a little background, i have glued together a joomla plugin using parts of joosco and the other plugin (by joomla tools)

basically, it is an updated joomla tools plugin that has been modified to operate as the currently logged in user.  Using the Joosco plugin,  joomla authenticates against Alfresco and the user holds an alf_ticket as a session ID.  Then, the joomlatools plugin use the alf_ticket it picked up for all its operations.   I also fixed the joomlatools to use the new WebPreview component (mostly).  To get this to work, i had to modify the webpreview.js file in share with a switch that detects if alf_ticket is floating around and if it is, use a url with the alf_ticket.  if not, use the original method url with no alf_ticket in the get

the situation is as follows

So, lets say i go into Share and upload 5 documents (2 page PDFs) then i do NOT look at the document page.  as a result, no preview/webpreview is generated. 

Next, i go into Joomla and navigate to one of those documents.  The web previewer loads, the swirly loading thing comes up and the document previews successfully.   Everything works as it should (as long as the preview hasn't been called anywhere before)

However, if i clear my browser cache, restart the browser and navigate back to the same document using the joomla plugin, the swirl will come up and then the preview will fail to load.  Its a generic fail to transfer/load the preview error. 

Now, if i go back into share and look at that document, the previewer always successfully loads the preview while in share.  whether it is cached locally or not.

now, if i go back to the joomla plugin and look at the document, the preview will work (i assume because it was still cached from the share page)

clear my cache again and it does not work in joomla until I go into Share and it gets cached

from what i can tell, the error message was generated within the WebPreviewer.swf and i have no idea where to start. 

Since i am running joomla on a separate server, i set the allowScripts in the instantiation of the previewer to All, so any site could make the previewer do things. 

I thought this would strip any cross site issues but apparently it hasn't. 


Any ideas?  Ill post the code somewhere if anyone wants to take a crack. 

Thanks

Adam
12 REPLIES 12

ofrxnz
Champ in-the-making
Champ in-the-making
I think this is the modified method i use to get the alf_ticket to work in web-preview.js

I set my Alfresco.constants.ALF_TICKET variable in PHP so i don't know what the proper way to do it in JS is. 

the main change from the default one is the addition of the if statement that detects the Alfresco.constants.ALF_TICKET variable. 

      _resolvePreview: function WP__resolvePreview(event)
      {
         var ps = this.options.previews;
         var webpreview = "webpreview", imgpreview = "imgpreview";
         var nodeRefAsLink = this.options.nodeRef.replace(":/", "");
         var argsNoCache = "?c=force&noCacheToken=" + new Date().getTime();
         var preview, url;
         if (this.options.mimeType.match(/^image\/\w+/))
         {
            /* Matched an image mimetype */
            if(undefined===window.Alfresco.constants.ALF_TICKET){
               url = Alfresco.constants.PROXY_URI + "api/node/" + nodeRefAsLink + "/content" + argsNoCache;
            }
            else
            {
               url = Alfresco.constants.PROXY_URI + "api/node/" + nodeRefAsLink + "/content" + argsNoCache + "&alf_ticket=" + Alfresco.constants.ALF_TICKET;
            }
            return (
            {
               url: url,
               paging: false
            });
         }
         else if (this.options.mimeType.match(/application\/x-shockwave-flash/))
         {
            if(undefined===window.Alfresco.constants.ALF_TICKET){
               url = Alfresco.constants.PROXY_URI + "api/node/content/" + nodeRefAsLink + argsNoCache + "&a=true";
            }
            else
            {
               url = Alfresco.constants.PROXY_URI + "api/node/content/" + nodeRefAsLink + argsNoCache + "&a=true&alf_ticket=" + Alfresco.constants.ALF_TICKET;
            }
            return (
            {
               url: url,
               paging: false
            });
         }
         else
         {
            preview = Alfresco.util.arrayContains(ps, webpreview) ? webpreview : (Alfresco.util.arrayContains(ps, imgpreview) ? imgpreview : null);
            if (preview != null)
            {
            if(undefined===window.Alfresco.constants.ALF_TICKET){
               url = Alfresco.constants.PROXY_URI + "api/node/" + nodeRefAsLink + "/content/thumbnails/" + preview + argsNoCache;
            }
            else
            {
               url = Alfresco.constants.PROXY_URI + "api/node/" + nodeRefAsLink + "/content/thumbnails/" + preview + argsNoCache + "&alf_ticket=" + Alfresco.constants.ALF_TICKET;
            }
               return (
               {
                  url: url,
                  paging: true
               });
            }
            return null;
         }
      }

As for the a=true part…..I have no idea…..maybe something to do with guest or anonymous access. Maybe i havnt found it but i is there was a concise list GET and POST arguments for each script and the engine in general….

yasosaran
Champ in-the-making
Champ in-the-making
I am not sure whether a=true is for anonymus or guest .

I copied the url in new IE window, it throwed me "no userd id found in session" error and it didn't open the document, neither prompted me for credentials.

Thanks.

ofrxnz
Champ in-the-making
Champ in-the-making
Yeah, I think i found the same thing. 

If you are already logged into share through the normal web interface, you get a cookie and the Scripting API uses that if it is available

I had to start using IE and FireFox at the same time to make sure it worked.  If it worked in IE, restart firefox, copy over the URL and see what happens….The only predictable one i found was the ticket

the GET authentication URL i posted returns XML data.  so if you know how to parse XML data in javascript you are golden.

Adam