We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22533
    • 41 Posts
    Hello everybody,

    Here is a french website that has a very cool style conerning its hyperlinks : Framasoft

    Pretty neat, isn’t it? wink

    I’d like to have the same kind of stuff on my website, unfortunately I don’t know PHP programming (I can read, but I can’t write!).

    The solution would be to create a simple plugin that adds OnWebPagePrerender a class attribute to every hyperlink in the [*content*] area, depending on if the href targets the website, wikipedia, or the web...

    So if anyone has the capacity and the motivation to write such a plugin, it would be really great! grin

    Thank you in advance!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      You could do this by adding various classnames to the links, then style the links with appropriate background images in your CSS.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 22533
        • 41 Posts
        That’s exactly what I want to do, but I was wondering if there was a way to do that automatically via a plugin.

        The code of that plugin should be something like this :

        for every <a> tag in the content area
            select case substring(href=)
                case "[(site_url)]" : class="internal"
                case "wikipedia" : class="wikipedia"
                other case : class="www"
            end select case
            insert in <a> tag the attribute class=...
        next <a>

        Maybe I could do this myself, but as I said, I’ve never done that much of PHP coding so I was hoping that a good coder would also be interested in doing this.

        Feedback welcome : are you interested in such plugin?
          • 10573
          • 101 Posts
          Quote from: P4T4T4 at Apr 04, 2007, 05:03 AM

          So if anyone has the capacity and the motivation to write such a plugin, it would be really great! grin

          Thank you in advance!
          Wow, I could really use that! I’m in the same boat you are, I can read, but not write. I’m humbled by all these smart developers!
            • 32942
            • 141 Posts
            hmm I’m quite sure you don’t need php for this tongue (altough it’s a nice to have)

            But I can recommend you following css rule like rthrash mentioned before:

            a.external:link, a.external {
                color: #444444;
                background: transparent url(../img/icons/filetypes/icon_external.gif) no-repeat center right;
                padding: 5px 20px 5px 0;
            }
            


            It will display an icon for any anchor with the class "external".
            So, it’s an easy to write the php stuff for that I think.
            The problem is only, that the page never knows if a link is external or interal.
            So you have to add following css rule also.


            a.internal:link, a.internal, a[href *="example.com/modx {
                color: #444444;
                background: transparent url(../img/icons/filetypes/icon_internal.gif) no-repeat center right;
                padding: 5px 20px 5px 0;
            }
            


            You may ask, why do you use classess if css itself can look for the parameters and add an icon, hehe don’t ask.
            You already guessed it, Internet Explorer prior v7 do not understand anything of a[href *="example.com/modx]

            hope this helps, it’s only a hint, not a solution.
            Just like you mentioned, the php thingy IS deffo betta.
            But not existant yet sad
              • 7923
              • 4,213 Posts
              Xsss4hell, the point was that the classes would be put to the links automatically during parsing.

              You’d need a regular expression that get’s all the links from the site and then looks if the url is internal or from external page, then put the classes to the links accordingly. I’m not very excellent in regexps so I’m not able to help, but I bet that with a bit of googling, you can find an example.


                "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                • 32942
                • 141 Posts
                Yeah right!

                This would be a cool plugin!
                But only, if you are able to extend the functionality as a normal "user".
                I mean the option to add icons for websites (myvideo.de, google.de...) or file-extensions (rar,mp3...) or protocolls (mailto://,icq://;https://)
                and so on. Blacklists (strike-through or remove links for spam ie.) are also welcome.
                CSS`s detetions mechanisms are not perfect and not supported by every browser.

                Whislist of usefull detections by the reg-ex:
                - protocol
                - file-extension
                - website
                - internal/external
                - blacklists
                - custom (favorites ie.)

                look at http://regexlib.com/
                  • 4626
                  • 57 Posts
                  The easiest might be to do it in javascript (the parsing of the html-dom isn’t very simple in php)...
                  A simple (non-elegant) way of doing this you can se in the followng code:
                  <html>
                  <head>
                  <style type="text/css">
                  	a.external {
                     	background: url("link_external.gif") no-repeat 0 0;
                     	padding-left: 15px;
                  	}
                  	a.internal {
                     	background: url("link_internal.png") no-repeat 0 0;
                     	padding-left: 15px;
                  	}
                  
                  	a.wikipedia {
                     	background: url("link_wikipedia.png") no-repeat 0 0;
                     	padding-left: 15px;
                  	}
                  	a.apple {
                  		background: url("link_apple.png") no-repeat 0 0;
                     	padding-left: 15px;
                     }
                  	img.hidden {
                  		display: none;
                  	}
                  
                  </style>
                  </head>
                  <body>
                  <p>
                  <a href="http://wikipedia.org/" title="....">Wikipedia</a><br />
                  <a href="nex.html" title="....">Internal</a><br />
                  <a href="http://www.apple.se/" title="....">Apple</a><br />
                  <a href="http://www.modxcms.com/" title="....">MODx</a><br />
                  
                  <img class="hidden" src="link_wikipedia.png" />
                  <img class="hidden" src="link_external.png" />
                  <img class="hidden" src="link_internal.png" />
                  <img class="hidden" src="link_apple.png" />
                  
                  <script type="text/javascript">
                  var targets = new Array();
                  targets[0] = new Array();
                  targets[0][0] = 'wikipedia';
                  targets[0][1] = /^http:\/\/[a-z\.]*wikipedia\.org/i;
                  targets[1] = new Array();
                  targets[1][0] = 'apple';
                  targets[1][1] = /^http:\/\/www\.apple\./i;
                  
                  var links = document.getElementsByTagName('a');
                  for (var i=0;i<links.length;i++) {
                  	if (links[i].href) {
                  		for (var j=0;j<targets.length;j++) {
                  			if (targets[j][1].test(links[i].href)) {
                  				links[i].className = targets[j][0];
                  				break;
                  			}
                  		}
                  		if (links[i].className == '') {
                  			var internal = /^http:\/\/localhost/i;
                  			if (internal.test(links[i].href)) {
                  				links[i].className = 'internal';
                  			} else {
                  				links[i].className = 'external';
                  			}
                  		}
                  	}
                  }
                  </script>
                  </body>
                  </html>
                  

                  Here I first define the css:
                  - Each possible type has it’s one definition – in this case ’internal, ’external’, ’wikipedia’ and ’apple’ and icons for these need to be supplied (I have attached them) and referenced correctly.
                  - The .hidden-class is to preload the images.

                  Then comes the body with the links and the hidden images.

                  After that i put the javascript (not good practice, but easy when not using a framework...).
                  - The additional types need to be defined in the targets-array as I’ve done with ’wikipedia’ and ’apple’
                  - The script goes through all the links and matches them to the regular expressions in the targets-array
                  - If a class is not defined for the link when it has gone through all the expressions it checks to see if it is an internal link (needs to be changed from ’localhost’ to something more appropriate) else it gives it the external-class.

                  With a javascript-framework you could make this a lot prettier, append a new class to the href instead of replacing it (which this script does) and you could put everything in an external js-file which you could build via a snippet in MODx.

                  Feel free to use the code as you like – I won’t do anything more with it (atleas not for a while) because I should be studying for my exams..

                  Ps. The images are taken from the referenced site without permission etc, likewise the apple-icon – so don’t use these on a live site without making sure you are allowed to use the images. Admins, please feel free to delete them if you see that it’s necessary. Ds.
                    • 18830
                    • 161 Posts
                    Using Pixy’s Rollovers http://wellstyled.com/css-nopreload-rollovers.html instead of several background images woud be even better. To mark different types of links you have to arrange the different icons vertically and not horizontally like shown at this little tutorial.

                    There are sometimes strange issues with the Safari browser and Pixy’s Rollovers. To avoid those make sure that there are really big spaces between the icons, i.e. at least 60 pixels.
                      • 16732
                      • 592 Posts
                      Here a little plugin to do that grin

                      Xternalinks