Announcement

Do not use the forums to submit bug reports, feature requests or patches, submit a New Ticket instead.

#1 2005-03-22 20:34:46

riftdesign
Xinha Pro
From: South Dakota, USA
Registered: 2005-03-22
Posts: 55
Website

Linker Question/Suggestion

I am trying to re-create Linker with a few different options. First let me say I love it! Second, the sites I have using xinha use mod_rewrite extensively and to say the least, scan.php just doesn't cut it for making links to pages. So, I have been trying to change Linker to allow for scan.php to have not only the url, but also text (like a page title and url), but without much luck.

What I would like to do is something of the sort:

[
    [
    ['/','General'],
        [
        ['/','Home'],
        ['/contact.php','Contact Us'],
        ['/staff/','Staff'],
        ['/links/','Links']
        ]
    ['/article/','Articles']
        [
        ['/article/','Article List'],
        ['/article/1/','Article Title 1'],
        ['/article/2/','Article Title 2'],
        ['/article/3/','Article Title 3'],
        ['/article/4/','Article Title 4'],
        ['/article/5/','Article Title 5']
        ]
    ]
]

I hope that made some sense. Basically, instead of a file directory, it is a webpage directory tree. It would be easy to write scan.php to create the needed data, but I am totally lost in the Linker javascript.

I guess what I am asking for is an alternative focus for Linker, where I can choose between a file directory listing or a webpage directory listing, having the file directory accepting file path only while webpage directory accepting both title and url.

I would be glad to help, but I am really lost in the code. Sorry.

Last edited by riftdesign (2005-03-22 20:36:10)


rift design studio
[url]http://www.riftdesign.com[/url]

Offline

#2 2005-03-23 00:21:54

Yermo
Xinha Authority
From: College Park, Md, USA
Registered: 2005-02-13
Posts: 143
Website

Re: Linker Question/Suggestion

riftdesign wrote:

I hope that made some sense. Basically, instead of a file directory, it is a webpage directory tree. It would be easy to write scan.php to create the needed data, but I am totally lost in the Linker javascript.

Actually, I have this exact functionality working here with an older version of the Linker plugin. The content management portion of the business platform (mobie) we've developed does exactly that.

I've also got the edit case working where if it's a link in the tree it highlights it. I haven't had a chance to make my changes backwards compatible with the default linker which is why I haven't checked it in yet.

It loops through all the files you send back. In my case I'm sending files back as a single string  from a modified scan.php as in:

['/,General'],
        [
        ['/,Home'],
        ['/contact.php,Contact Us'],
        ['/staff/,Staff'],
        ['/links/,Links']
        ]

So each string has the name to be displayed in the tree and the value to assign as a single string separated by a comma. It's a major kludge ...

The trick is then in makeNodes(). Each string from  your array is an entry in the files[] argument.

Linker.Dialog.prototype.makeNodes = function(files, parent)
{
  for(var i = 0; i < files.length; i++)
  {

    if(typeof files[i] == 'string')
    {

     // the text to display is separated from the link by a ,
         // file_args[0] == string to display
         // file_args[1] == string to set in the URL.

     var file_args  = files[i].split(',');

      this.dTree.add(Linker.nxtid++, 
                            parent,
                     file_args[0].replace(/^.*\//, ''),
                     'javascript:document.getElementsByName(\'' + this.dialog.id.href + '\')[0].value=unescape(\'' + escape(file_args[1]) + '\');document.getElementsByName(\'' + this.dialog.id.type + '\')[0].click();document.getElementsByName(\'' + this.dialog.id.href + '\')[0].focus();void(0);',
                     file_args[1]);

    }
    else
    {

    // this entry in files is an array, so we recurse.

     var file_args = files[i][0].split(',');

      var id = this.Dialog_nxtid++;
      this.dTree.add(id, parent, file_args[0].replace(/^.*\//, ''), null, file_args[0]);
      this.makeNodes(files[i][1], id);
    }
  }
}

Hopefully this will help you get over the hump.

Contact me at http://www.formvista.com/contact.html if you get stuck; I can email you what I have.

-- Yermo


-----------------------------------------------------------------------------------------
Content Management with Business Intelligence      [url]http://www.formvista.com[/url]

Offline

#3 2005-03-23 02:50:23

riftdesign
Xinha Pro
From: South Dakota, USA
Registered: 2005-03-22
Posts: 55
Website

Re: Linker Question/Suggestion

Yermo,

I implemented the changes you suggest and have had some success...here's the code I have at this time:

Linker.Dialog.prototype.makeNodes = function(files, parent)
{
  for(var i = 0; i < files.length; i++)
  {
    if(typeof files[i] == 'string')
    {
     // the text to display is separated from the link by a ,
     // file_args[0] == string to display
     // file_args[1] == string to set in the URL.
     var file_args  = files[i].split(',');
     this.dTree.add(Linker.nxtid++, parent, 
                     file_args[1].replace(/^.*\//, ''),
                    'javascript:document.getElementsByName(\'' + this.dialog.id.href + '\')[0].value=unescape(\'' + escape(file_args[0]) + '\');document.getElementsByName(\'' + this.dialog.id.type + '\')[0].click();document.getElementsByName(\'' + this.dialog.id.href + '\')[0].focus();void(0);',
                    file_args[0]);
    }
    else
    {
    // this entry in files is an array, so we recurse.
     var file_args = files[i][0].split(',');
     var id = this.Dialog_nxtid++;
     this.dTree.add(id, parent, file_args[0].replace(/^.*\//, ''), null, file_args[0]);
     this.makeNodes(files[i][1], id);
    }
  }
}

I have scan.php generating the following data scenarios:

SCENARIO 1:
['/,General']

SCENARIO 2:
['/,General'],[['/,Home'],['/contact.php,Contact Us'],['/staff/,Staff'],['/links/,Links']]

In Scenario 1, things work as planned...but Scenario 2 borks the code...

Error: files has no properties
Source File: http://domain.com/js/xinha/plugins/Linker/linker.js
Line: 398

Line 398 is

  for(var i = 0; i < files.length; i++)

of the Linker.Dialog.prototype.makeNodes section.

Any thoughts?


rift design studio
[url]http://www.riftdesign.com[/url]

Offline

#4 2005-03-23 03:04:14

guillaumed
Xinha Administrator
From: Lyon, France
Registered: 2005-02-23
Posts: 85

Re: Linker Question/Suggestion

Hi,

As more and more php interfaces are created with Xhina, what do you think of formalize a little bit more the interaction between them? I personally don't use php but java with tomcat (no pb) but I think that if we can define an XML interface generic for all plugins it should be great...

No?

Offline

#5 2005-03-23 03:45:00

Yermo
Xinha Authority
From: College Park, Md, USA
Registered: 2005-02-13
Posts: 143
Website

Re: Linker Question/Suggestion

SCENARIO 1:
['/,General']

SCENARIO 2:
['/,General'],[['/,Home'],['/contact.php,Contact Us'],['/staff/,Staff'],['/links/,Links']]

Yea, the way this is set up you need to add a directory name so it should be

['General,/',[ 'Home, directory_name', ['Home,/', 'Contact Us,/contact.php', ...

I ran into the same problem ..

Last edited by Yermo (2005-03-23 03:55:44)


-----------------------------------------------------------------------------------------
Content Management with Business Intelligence      [url]http://www.formvista.com[/url]

Offline

#6 2005-03-23 04:39:20

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

Re: Linker Question/Suggestion

plase take a look at this thicket:
http://xinha.gogo.co.nz/cgi-bin/trac.cgi/ticket/67
i wrote allready a little patch, and gogo had a better idea big_smile
(a patch for the new version from gogo hasn't been written yet i think)


Niko

Offline

#7 2005-03-23 04:46:46

Yermo
Xinha Authority
From: College Park, Md, USA
Registered: 2005-02-13
Posts: 143
Website

Re: Linker Question/Suggestion

niko wrote:

plase take a look at this thicket:
http://xinha.gogo.co.nz/cgi-bin/trac.cgi/ticket/67
i wrote allready a little patch, and gogo had a better idea big_smile
(a patch for the new version from gogo hasn't been written yet i think)

Yea, my approach was just a quick hack ...


-----------------------------------------------------------------------------------------
Content Management with Business Intelligence      [url]http://www.formvista.com[/url]

Offline

#8 2005-03-23 06:19:17

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

Re: Linker Question/Suggestion

i just wrote the patch...
http://xinha.gogo.co.nz/cgi-bin/trac.cgi/ticket/67

scan.php should return code like this:

[
"e.html",
['f.html', ['g.html','h.html']],
{url:'i.html',title:'I Html'},
{url:'j.html',title:'J Html', children:[{url:'k.html',title:"K Html"},'l.html',['m.html',['n.html']]]}
]

niko


Niko

Offline

#9 2005-03-24 20:41:08

riftdesign
Xinha Pro
From: South Dakota, USA
Registered: 2005-03-22
Posts: 55
Website

Re: Linker Question/Suggestion

niko wrote:

plase take a look at this thicket:
http://xinha.gogo.co.nz/cgi-bin/trac.cgi/ticket/67
i wrote allready a little patch, and gogo had a better idea big_smile
(a patch for the new version from gogo hasn't been written yet i think)

I have applied the patch and have tried the methods described above without success. Are you currently using the same patch and the scan.php data that you mentioned?


rift design studio
[url]http://www.riftdesign.com[/url]

Offline

#10 2005-03-25 03:09:42

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

Re: Linker Question/Suggestion

yes, exactly.
what is not working for you?
do you get JS-errors?


Niko

Offline

#11 2005-03-25 13:25:58

riftdesign
Xinha Pro
From: South Dakota, USA
Registered: 2005-03-22
Posts: 55
Website

Re: Linker Question/Suggestion

I don't have any JS errors, but Linker cannot parse the data and therefore doesn't do anything. This might be another issue to address for Linker (no parser feedback). I used your example for data from scan.php and I got nothing. When I click on the create hyperlink button, nothing happens. The same thing will happen if scan.php returns ill-formed data.


rift design studio
[url]http://www.riftdesign.com[/url]

Offline

#12 2005-03-25 13:30:20

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

Re: Linker Question/Suggestion

what happens if you use

[
"e.html","f.html"
]

or

[
"e.html",
['f.html', ['g.html','h.html']]
]

does these work?


Niko

Offline

#13 2005-03-25 13:31:03

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

Re: Linker Question/Suggestion

....and in FF what does you tell the JS-Console?


Niko

Offline

#14 2005-03-25 13:47:23

riftdesign
Xinha Pro
From: South Dakota, USA
Registered: 2005-03-22
Posts: 55
Website

Re: Linker Question/Suggestion

Well, nevermind...the JS must have been cached. It's working now. Thanks for helping Niko!


rift design studio
[url]http://www.riftdesign.com[/url]

Offline

#15 2005-03-25 17:02:34

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

Re: Linker Question/Suggestion

ah, great big_smile
hopefully gogo will apply the patch soon big_smile


Niko

Offline

#16 2005-03-25 18:27:08

riftdesign
Xinha Pro
From: South Dakota, USA
Registered: 2005-03-22
Posts: 55
Website

Re: Linker Question/Suggestion

I still think there should be some kind of feedback if there is a malformed data source from scan.php. Maybe showing the dialog but with an error listed where the tree is would suffice.


rift design studio
[url]http://www.riftdesign.com[/url]

Offline

#17 2005-03-25 18:50:39

riftdesign
Xinha Pro
From: South Dakota, USA
Registered: 2005-03-22
Posts: 55
Website

Re: Linker Question/Suggestion

Could have a problem here...If the title has a single quote in the title (ie: Bob's Corner), it will not parse, and as mentioned earlier, there is no feedback as to the failure. I tried escaping the single quote with \' but that didn't seem to work either. Any thoughts here?

[
{url:'/',title:'Home', children:[{url:'/index.php',title:'Home'}, {url:'/calendar/',title:'Calendar'}, {url:'/contact.php',title:'Contact'}, {url:'/links/index.php',title:'Links'}]},
{url:'/ministry/children/',title:'Bob\'s Corner', children:[{url:'/ministry/children/',title:'Bob\'s Corner'}]}
]

Last edited by riftdesign (2005-03-25 18:53:20)


rift design studio
[url]http://www.riftdesign.com[/url]

Offline

#18 2005-03-29 00:43:34

dhscompguy
Xinha Community Member
Registered: 2005-03-10
Posts: 23

Re: Linker Question/Suggestion

You could do something like this in PHP --

htmlentities($title, ENT_QUOTES);

Learn how to astral project: [url]http://gnosticweb.org[/url]

Offline

#19 2005-03-29 01:00:32

riftdesign
Xinha Pro
From: South Dakota, USA
Registered: 2005-03-22
Posts: 55
Website

Re: Linker Question/Suggestion

dhscompguy wrote:

You could do something like this in PHP --

htmlentities($title, ENT_QUOTES);

I don't know why that slipped my mind...thanks for the reminder. It worked great.


rift design studio
[url]http://www.riftdesign.com[/url]

Offline

#20 2005-03-29 02:03:50

guillaumed
Xinha Administrator
From: Lyon, France
Registered: 2005-02-23
Posts: 85

Re: Linker Question/Suggestion

Hi,

I give you too interesting links for this discussion

http://www.sitepoint.com/blog-post-view.php?id=191776
http://www.sitepoint.com/blog-post-view.php?id=165367

And also

http://developer.apple.com/internet/web … frame.html

Hope they will help to not reinvent the wheel...

Offline

#21 2005-03-29 07:45:48

noxi
New member
From: Denmark
Registered: 2005-03-26
Posts: 9
Website

Re: Linker Question/Suggestion

guillaumed wrote:

Hi,

As more and more php interfaces are created with Xhina, what do you think of formalize a little bit more the interaction between them? I personally don't use php but java with tomcat (no pb) but I think that if we can define an XML interface generic for all plugins it should be great...

No?

I think thats great idea (i myself use modperl). It would would allow JS scripts not being altered and thus easier to update / share between different CMS systems.

U should start a ticket thingie bout it smile


[i]To live is to die ...[/i]

Offline

#22 2005-03-29 23:19:06

g2010a
New member
Registered: 2005-03-28
Posts: 9

Re: Linker Question/Suggestion

how do you return an "object" from PHP to Javascript?

Offline

#23 2005-03-30 10:43:34

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

Re: Linker Question/Suggestion

you don't return a PHP-Object, you return a JavaScript-Code that represents an object (if executed)
which means you return a string like

{ 'index': 'value', 'foo': 'bar' }

so you return an object from php to js big_smile


Niko

Offline

#24 2005-03-31 14:01:37

g2010a
New member
Registered: 2005-03-28
Posts: 9

Re: Linker Question/Suggestion

ok, thanks. So, would the following code work in scan.php? I seem to have difficulty grasping this concept of passing 'objects' between languages...

<?php
    ....
    $linkArray[] = "e.html";
    $linkArray[] = "{url:'/',title:'Home', children:[{url:'/index.php',title:'Home'}]}";

    echo to_js($linkArray);
?>

I bring this up because it keeps thinking it's a string, and I think I have applied the patch posted.  If you have a direct link to the linker.js file that will interpret this correctly, please let me know. Thanks!

Last edited by g2010a (2005-03-31 14:28:27)

Offline

#25 2005-04-01 06:04:18

niko
Xinha Authority
From: Salzburg/Austria
Registered: 2005-02-14
Posts: 338

Re: Linker Question/Suggestion

i wrote a additional patch for scan.php, take a look at it:

http://xinha.python-hosting.com/ticket/67

you can use the to_js function directly...


Niko

Offline

Board footer

Powered by FluxBB