We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

WYGWAM Internal Link List

Development and Programming

theVitalPath's avatar
theVitalPath
23 posts
16 years ago
theVitalPath's avatar theVitalPath

THE WHAT Added the ability to link to internal pages created in ExpressionEngine through WYGWAM (get it from Pixel & Tonic - WYGWAM).

THE WHY TinyMCE had the ability to include a link list for EE, but lacked in many other areas which I won’t get into. WYGWAM has been great so far, but was lacking the ability for users to be able to easily link to other sections of their site (unless they copy/pasted their URLs).

QUICK NOTE A few people have already been asking about the details of this, so I’m writing this just to get everyone going, but I will be cleaning up my code more and making things a little more robust for future use…which I will post onto this thread.

Also, I did send Brandon Kelly (WYGWAM’s developer) a note and received his permission to put this up (without giving away the core WYGWAM files obviously).

THE HOW There are a few changes that are required:

  1. in /themes/wygwam/lib/ckeditor/ckeditor.js search for the word “link.js” (there is only one instance of it) and change it to “link.php”

  2. find /themes/wygwam/lib/ckeditor/plugins/link/dialogs/link.js and rename it to link_bk.js just to have it as a backup

  3. now, download the following PHP file and place it in /themes/wygwam/lib/ckeditor/plugins/link/dialogs/ (so now you have a link.php file in there)

  4. go to the PHP file (link.php) and make the necessary adjustments to the very top of the code so that it works with your DB connections and settings (replace “username”, “password”, “database_name” with your info and also update the statuses that you want to pull if you have your own custom statuses beyond open)

  5. That’s it…now, when you select a piece of text, click on the Link button, and from the dropdown of options for URL, Email, etc. you will also have one called “Interior Page”…once you select that, you will get another dropdown that displays all of your interior pages. Simply select one and click OK…all should be set now.

BUGS & SO ON There will likely be bugs based on certain setups and so on and I also haven’t done this for EE2 yet (not sure how it will change) nor MSM, but let me know if you have any problems and I’ll try to help out to the best of my abilities. If you do come up with changes to my code that will make things even better, please post it here so that everyone else can access it too…sharing is caring! 😊

Also, the code changes are really easy and happen mainly at the very top and between lines 368 and 386 of link.php.

Cheers! Dan

       
Brian Litzinger's avatar
Brian Litzinger
711 posts
16 years ago
Brian Litzinger's avatar Brian Litzinger

Where does it get it’s interior pages list from? EE doesn’t have pages (aside from Pages & Structure modules).

       
theVitalPath's avatar
theVitalPath
23 posts
16 years ago
theVitalPath's avatar theVitalPath

Right now, it uses the table “exp_sites” and the field “site_pages” from that table which holds a serialized array of your internal page links (which is used to build the actual URLs to assign to the links).

I also used the table “exp_weblog_titles” to get a list of the weblog entry titles with their associated entry_ids and then use that entry_id for finding the correct URL path from the array of links in the “site_pages” field of the “exp_sites” table.

I think this can be done in a better fashion but I just wanted to get this up and running which it does.

Hopefully that makes sense…let me know 😊

ps - btw, by using the exp_sites table, it won’t matter if you use Pages or Structure…I currently use Structure myself and it works like a charm.

       
Brian Litzinger's avatar
Brian Litzinger
711 posts
16 years ago
Brian Litzinger's avatar Brian Litzinger

I added the same feature to the next version of WYMEditor, just haven’t released it yet though. Funny someone else was working on the same thing.

       
theVitalPath's avatar
theVitalPath
23 posts
16 years ago
theVitalPath's avatar theVitalPath

one other note: between lines 368-386, you may want to use addslashes to avoid any errors if any of your weblog entries have apostrophe’s in them

       
Chris Brauckmuller's avatar
Chris Brauckmuller
35 posts
16 years ago
Chris Brauckmuller's avatar Chris Brauckmuller

Dan, This is very helpful! Great to know it works with Structure, I’m in the process of building my first Structure-based site right now and I’m very pleased to hear that the internal link list will work with Structure.

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen

Hi Dan,

Just wanted to say thanks for the addition here. I currently have a site running Structure and getting the client to place links in themselves would be a total headache. This is fantastic and makes everything exceptionally easy now.

Would be great if this was added into the core codebase of Wygwam. Did you ask Brandon about that?

One thing that I was wondering is would there be any way of limiting this to certain weblogs? I only ask as I have a weblog on the site which is used as a gallery and as such is one entry per image. There are likely to be many many images on the site so having all those in the drop-down list would be a bit of a headache especially as they would never need to be linked to. Just a thought though.

Best wishes,

Mark

       
theVitalPath's avatar
theVitalPath
23 posts
16 years ago
theVitalPath's avatar theVitalPath

@chris: hey chris, glad you like it…I’ll be updating it so that it also indents subnavs properly in the dropdown and makes it a little more user friendly than just a super long list of pages.

@mark: thanks for the feedback! glad you like it…I have sent the information over to Brandon, but I’m not sure how he would like to incorporate it into the core WYGWAM files…hopefully it gets added soon as I’m sure most people would find this useful.

As for limiting certain weblogs, this can certainly be done:

Replace (at the top of link.php):

$result = mysql_query("SELECT entry_id as id, title as title FROM exp_weblog_titles WHERE status IN ('open', 'Sub Menu')");

With this query instead:

$result = mysql_query("SELECT a.entry_id as id, a.title as title FROM exp_weblog_titles as a, exp_weblogs as b WHERE a.status IN ('open', 'Sub Menu') AND a.weblog_id = b.weblog_id AND b.blog_name IN ('pages')");

And in the last part of that query, add the weblog names you want included (ie. ‘pages’, ‘weblognameA’, ‘weblognameB’, etc.)

Hope that helps!

Cheers, Dan

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen
As for limiting certain weblogs, this can certainly be done: Replace (at the top of link.php):
$result = mysql_query("SELECT entry_id as id, title as title FROM exp_weblog_titles WHERE status IN ('open', 'Sub Menu')");
With this query instead:
$result = mysql_query("SELECT a.entry_id as id, a.title as title FROM exp_weblog_titles as a, exp_weblogs as b WHERE a.status IN ('open', 'Sub Menu') AND a.weblog_id = b.weblog_id AND b.blog_name IN ('pages')");
And in the last part of that query, add the weblog names you want included (ie. ‘pages’, ‘weblognameA’, ‘weblognameB’, etc.)

Thanks Dan. That works perfectly.

Would be great if you could somehow create an extension or settings page for this though so that you don’t have to edit the link.php file each time you add a new weblog entry. Don’t know if that’s possible though?

Best wishes,

Mark

       
theVitalPath's avatar
theVitalPath
23 posts
16 years ago
theVitalPath's avatar theVitalPath

glad it worked out mark…i never really thought about building an extension/setting page for this because im hoping that Brandon incorporates it into WYGWAM and the settings can be adjusted from there. But if he decides not to, I’ll definitely look into that.

ps - doozazzle 😉

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
16 years ago
Mark Bowen's avatar Mark Bowen
glad it worked out mark…i never really thought about building an extension/setting page for this because im hoping that Brandon incorporates it into WYGWAM and the settings can be adjusted from there. But if he decides not to, I’ll definitely look into that.

That would be great, thanks.

ps - doozazzle 😉

Thanks too for the view 😉

Best wishes,

Mark

       
Jarrett Barnett's avatar
Jarrett Barnett
31 posts
about 16 years ago
Jarrett Barnett's avatar Jarrett Barnett

This was exactly what WYGWAM (and any other WYSIWYG editor) has been missing. An absolute need for clients.

One improvement perhaps could be a better way to visual display a tree format, maybe with the use of hyphens (representing each level).

Maybe something like this?

-Home Page -Page 1 –Inner Page —Child Page —Child Page 2 —Child page 3 –Inner Page 2 –Inner Page 3 —Another Child —Another Child 2

Besides that however, it’s great!

       
Jarrett Barnett's avatar
Jarrett Barnett
31 posts
about 16 years ago
Jarrett Barnett's avatar Jarrett Barnett

I also found that it automatically throws in the full URL which isn’t good for sites where I want to keep it using https:// – (and I prefer using relative URLs anyway).

To make it use just the “relative path”, simply add the following:

(Create a new line after line 18, and add the following to line 19 (should be empty):

$relative_url = true;

Then on line 379-381, replace the following 3 lines:

$url = $site_url.$site_index.$page;
$tmp = str_replace('http://', '', $url);
$url = 'http://'.str_replace('//', '/', $tmp);

WITH just this ONE line:

$url = ($relative_url) ? str_replace('//', '/', .'/'.$site_index.$page) : 'http://'.str_replace(array('http://', '//'), array('', '/'), $site_url.$site_index.$page);

Should you ever want to go back to using the full url, simply replace the “true” on line 18 to “false”.

       
theVitalPath's avatar
theVitalPath
23 posts
about 16 years ago
theVitalPath's avatar theVitalPath

Thanks for the addition Jarrett…I’m not sure if Brandon will still be adding this feature to the default build, so I’m leaning towards building a settings page or extending the options in the custom field setup so that users can select absolute/relative paths, weblogs to include (or option for all), status limitations, etc.

And I’m almost finished with the indented tree format to make finding things easier…I’ll post once I’m done.

Cheers, Dan

       
Jarrett Barnett's avatar
Jarrett Barnett
31 posts
about 16 years ago
Jarrett Barnett's avatar Jarrett Barnett

Yeah ideally it would be controlled as an “advanced” setting option which is already part of the WYGWAM 2.0.

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.