Author Topic: External links using admin  (Read 1159 times)

abicio

  • Newbie
  • *
  • Posts: 27
  • Karma: +0/-0
    • View Profile
External links using admin
« on: October 27, 2009, 09:12:49 AM »
Are the external links menu included in the 1.3.3?  ::)  ;D
« Last Edit: October 27, 2009, 07:23:13 PM by Xander »

Xander

  • Developer
  • Administrator
  • Full Member
  • *****
  • Posts: 240
  • Karma: +5/-0
    • View Profile
    • CompactCMS.nl
Re: External links using admin
« Reply #1 on: October 28, 2009, 01:41:04 AM »
I have thought of a solution that isn't too difficult. I'd like you to test it for me and tell me whether this would work for you. I've decided to take this approach, because items such as the page title and description are unnecessary when you use the link for an external link anyway.

So what this is going to do is this: if you enter a URL in the description field (e.g. http://www.compactcms.nl), it will make the item in the menu point to this URL directly.

- Open up ./lib/sitemap.php
- Find this code (towards the bottom)


	
while (
$row mysql_fetch_assoc($map_result)):
	
	
if(
$row['sublevel']=="0") {
	
	
	
$istop = ($row['urlpage']==$curr_page)?'class="current"':null;
	
	
	
if(
$row['islink']=="N") {
	
	
	
	
$ccms['structure'][$i] .= "<li><a $istop href=\"#\" title=\"".ucfirst($row['subheader'])."\">".ucfirst($row['pagetitle'])."</a>";
	
	
	
} elseif(
$row['islink']=="Y" && $row['urlpage']!=$cfg['homepage']) {
	
	
	
	
$ccms['structure'][$i] .= "<li><a $istop href=\"".$row['urlpage'].".html\" title=\"".ucfirst($row['subheader'])."\">".ucfirst($row['pagetitle'])."</a>";
	
	
	
} elseif(
$row['islink']=="Y" && $row['urlpage']==$cfg['homepage']) {
	
	
	
	
$istop = (!isset($curr_page))?'class="current"':null;
	
	
	
	
$ccms['structure'][$i] .= "<li><a $istop href=\"./\" title=\"".ucfirst($row['subheader'])."\">".ucfirst($row['pagetitle'])."</a>";
	
	
	
}
	
	
	

	
	
	
$sub_result mysql_query("SELECT * FROM `pages` WHERE `toplevel` = '".$row['toplevel']."' AND `sublevel`!='0' AND `menu_id` = '$i' AND `islink` = 'Y' ORDER BY `sublevel` ASC"$link);
	
	
	
if(
mysql_num_rows($sub_result)>"0") {
	
	
	
	
$ccms['structure'][$i] .= "<ul class=\"sublevel\">";
	
	
	
	
while (
$sub mysql_fetch_assoc($sub_result)):
	
	
	
	
	
$issub = ($sub['urlpage']==$curr_page)?'class="current"':null;
	
	
	
	
	
$ccms['structure'][$i] .= "<li><a $issub href=\"".$sub['urlpage'].".html\" title=\"".ucfirst($sub['subheader'])."\">".ucfirst($sub['pagetitle'])."</a></li>";
	
	
	
	
endwhile;
	
	
	
	
$ccms['structure'][$i] .= "</ul></li>";
	
	
	
} elseif(
mysql_num_rows($sub_result)=="0") {
	
	
	
	
$ccms['structure'][$i] .= "</li>";
	
	
	
}
	
	
}
	
endwhile;


- Replace it with the following lines:


	
while (
$row mysql_fetch_assoc($map_result)):
	
	
if(
$row['sublevel']=="0") {
	
	
	
$istop = ($row['urlpage']==$curr_page)?'class="current"':null;
	
	
	
$extop = (preg_match('/^(http(s?):\/\/{1})((\w+\.){1,})\w{2,}(\/?)$/i'$row['description']))?true:false;
	
	
	
if(
$row['islink']=="N") {
	
	
	
	
$ccms['structure'][$i] .= "<li><a $istop href=\"#\" title=\"".ucfirst($row['subheader'])."\">".ucfirst($row['pagetitle'])."</a>";
	
	
	
} elseif(
$row['islink']=="Y" && $row['urlpage']!=$cfg['homepage'] && $extop===false) {
	
	
	
	
$ccms['structure'][$i] .= "<li><a $istop href=\"".$row['urlpage'].".html\" title=\"".ucfirst($row['subheader'])."\">".ucfirst($row['pagetitle'])."</a>";
	
	
	
} elseif(
$row['islink']=="Y" && $row['urlpage']!=$cfg['homepage'] && $extop===true) {
	
	
	
	
$ccms['structure'][$i] .= "<li><a $istop href=\"".$row['description']."\" title=\"".ucfirst($row['subheader'])."\">".ucfirst($row['pagetitle'])."</a>";
	
	
	
} elseif(
$row['islink']=="Y" && $row['urlpage']==$cfg['homepage']) {
	
	
	
	
$istop = (!isset($curr_page))?'class="current"':null;
	
	
	
	
$ccms['structure'][$i] .= "<li><a $istop href=\"./\" title=\"".ucfirst($row['subheader'])."\">".ucfirst($row['pagetitle'])."</a>";
	
	
	
}
	
	
	

	
	
	
$sub_result mysql_query("SELECT * FROM `pages` WHERE `toplevel` = '".$row['toplevel']."' AND `sublevel`!='0' AND `menu_id` = '$i' AND `islink` = 'Y' ORDER BY `sublevel` ASC"$link);
	
	
	
if(
mysql_num_rows($sub_result)>"0") {
	
	
	
	
$ccms['structure'][$i] .= "<ul class=\"sublevel\">";
	
	
	
	
while (
$sub mysql_fetch_assoc($sub_result)):
	
	
	
	
	
$issub = ($sub['urlpage']==$curr_page)?'class="current"':null;
	
	
	
	
	
$exsub = (preg_match('/^(http(s?):\/\/{1})((\w+\.){1,})\w{2,}(\/?)$/i'$sub['description']))?true:false;
	
	
	
	
	
if(
$exsub===false) { 
	
	
	
	
	
	
$ccms['structure'][$i] .= "<li><a $issub href=\"".$sub['urlpage'].".html\" title=\"".ucfirst($sub['subheader'])."\">".ucfirst($sub['pagetitle'])."</a></li>";
	
	
	
	
	
} elseif(
$exsub===true) {
	
	
	
	
	
	
$ccms['structure'][$i] .= "<li><a $issub href=\"".$sub['description']."\" title=\"".ucfirst($sub['subheader'])."\">".ucfirst($sub['pagetitle'])."</a></li>";
	
	
	
	
	
}
	
	
	
	
endwhile;
	
	
	
	
$ccms['structure'][$i] .= "</ul></li>";
	
	
	
} elseif(
mysql_num_rows($sub_result)=="0") {
	
	
	
	
$ccms['structure'][$i] .= "</li>";
	
	
	
}
	
	
}
	
endwhile;


I'll let you do the honours of testing it and reporting back to me. If this satisfies your needs I'll develop it further and put it in 1.3.3.

Thanks!
Xander.
Don't ever hold back your suggestions. Help me either to improve CompactCMS or spread the word about it on sites such as Twitter, Digg, StumbleUpon, etc :). Thanks!

abicio

  • Newbie
  • *
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: External links using admin
« Reply #2 on: November 19, 2009, 05:22:58 PM »
I haven't tried yet, I hope to have time to work on it in the next days  ;)

abicio

  • Newbie
  • *
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: External links using admin
« Reply #3 on: December 04, 2009, 12:18:37 AM »
Nice...I've just seen that you implemented the solution in the new version... great  ;)

but...

how can I open the new link in a new window?  (target=_blank)  ::) :)

Xander

  • Developer
  • Administrator
  • Full Member
  • *****
  • Posts: 240
  • Karma: +5/-0
    • View Profile
    • CompactCMS.nl
Re: External links using admin
« Reply #4 on: December 05, 2009, 03:28:42 PM »
You just don't give up, do you ;)..

But you have a good point. By default it is not "best practice" to decide for your user whether a site should open in the current window or new window. This is why a website will not validate if the source includes a target="". However, you should be able to do it of course, so I thought of a fix that also by-passes the W3C validator check :). I just uploaded a new built (just download from main site). The only updated file is ./lib/sitemap.php (overwrite your current one). What this does is add a rel="external" to each external link.

If you now add this Javascript to your template or external JS file, all rel="externals" will be translated into target="_blank".

Code: [Select]
<![CDATA[
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;
]]>

Hope this helps! Not the easiest solution, but as said: specifying targets is "not done" and therefore I can't make it a default option.

Cheers!
Xander.
« Last Edit: December 06, 2009, 11:00:04 PM by Xander »
Don't ever hold back your suggestions. Help me either to improve CompactCMS or spread the word about it on sites such as Twitter, Digg, StumbleUpon, etc :). Thanks!

abicio

  • Newbie
  • *
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: External links using admin
« Reply #5 on: December 05, 2009, 11:29:11 PM »
thanks  ;D

youcantryreachingme

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +1/-0
    • View Profile
Re: External links using admin
« Reply #6 on: December 10, 2009, 02:20:03 AM »
but as said: specifying targets is "not done"

You're the first person I know to quote this "best practice" - well done!

While I agree with the principal... I still use _blank for off-site links :D  It makes good business sense!

Chris.

abicio

  • Newbie
  • *
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: External links using admin
« Reply #7 on: December 10, 2009, 03:56:20 PM »
but as said: specifying targets is "not done"

You're the first person I know to quote this "best practice" - well done!

While I agree with the principal... I still use _blank for off-site links :D  It makes good business sense!

Chris.

I quote everything  :D