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:
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”
find /themes/wygwam/lib/ckeditor/plugins/link/dialogs/link.js and rename it to link_bk.js just to have it as a backup
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)
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)
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
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.
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
@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
As for limiting certain weblogs, this can certainly be done: Replace (at the top of link.php):With this query instead:$result = mysql_query("SELECT entry_id as id, title as title FROM exp_weblog_titles WHERE status IN ('open', 'Sub Menu')");And in the last part of that query, add the weblog names you want included (ie. ‘pages’, ‘weblognameA’, ‘weblognameB’, etc.)$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')");
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
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 😉
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
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!
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”.
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
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.