[geeklog-cvs] geeklog: Added canonical link for article directory

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Mon Apr 20 08:13:43 EDT 2009


details:   http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/5f138083df5a
changeset: 6969:5f138083df5a
user:      Dirk Haun <dirk at haun-online.de>
date:      Sun Apr 19 13:50:33 2009 +0200
description:
Added canonical link for article directory

diffstat:

1 file changed, 36 insertions(+), 6 deletions(-)
public_html/directory.php |   42 ++++++++++++++++++++++++++++++++++++------

diffs (78 lines):

diff -r a9b4ce455fdf -r 5f138083df5a public_html/directory.php
--- a/public_html/directory.php	Sun Apr 19 12:16:59 2009 +0200
+++ b/public_html/directory.php	Sun Apr 19 13:50:33 2009 +0200
@@ -51,7 +51,7 @@
                                 COM_getBlockTemplate ('_msg_block', 'header'));
     $login = new Template ($_CONF['path_layout'] . 'submit');
     $login->set_file (array ('login' => 'submitloginrequired.thtml'));
-    $login->set_var ( 'xhtml', XHTML );
+    $login->set_var ('xhtml', XHTML);
     $login->set_var ('site_url', $_CONF['site_url']);
     $login->set_var ('layout_url', $_CONF['layout_url']);
     $login->set_var ('login_message', $LANG_LOGIN[2]);
@@ -449,6 +449,35 @@
     return $retval;
 }
 
+/**
+* Return a canonical link
+*
+* @param    string  $topic  current topic or 'all'
+* @param    int     $year   current year
+* @param    int     $month  current month
+* @return   string          <link rel="canonical"> tag
+*
+*/
+function DIR_canonicalLink($topic, $year = 0, $month = 0)
+{
+    global $_CONF;
+
+    $script = $_CONF['site_url'] . '/' . THIS_SCRIPT;
+
+    $tp = '?topic=' . urlencode($topic);
+    $parts = '';
+    if (($year != 0) && ($month != 0)) {
+        $parts .= "&year=$year&month=$month";
+    } elseif ($year != 0) {
+        $parts .= "&year=$year";
+    } elseif ($topic == 'all') {
+        $tp = '';
+    }
+    $url = COM_buildUrl($script . $tp . $parts);
+
+    return '<link rel="canonical" href="' . $url . '"' . XHTML . '>' . LB;
+}
+
 // MAIN
 $display = '';
 
@@ -487,7 +516,8 @@
     if ($topic != 'all') {
         $title .= ': ' . $topicName;
     }
-    $display .= COM_siteHeader ('menu', $title);
+    $display .= COM_siteHeader('menu', $title,
+                               DIR_canonicalLink($topic, $year, $month));
     $display .= DIR_displayMonth ($topic, $year, $month, true);
     $display .= DIR_navBar ($topic, $year, $month);
 } else if ($year != 0) {
@@ -495,15 +525,15 @@
     if ($topic != 'all') {
         $title .= ': ' . $topicName;
     }
-    $display .= COM_siteHeader ('menu', $title);
-    $display .= DIR_displayYear ($topic, $year, true);
-    $display .= DIR_navBar ($topic, $year);
+    $display .= COM_siteHeader('menu', $title, DIR_canonicalLink($topic, $year));
+    $display .= DIR_displayYear($topic, $year, true);
+    $display .= DIR_navBar($topic, $year);
 } else {
     $title = $LANG_DIR['title'];
     if ($topic != 'all') {
         $title .= ': ' . $topicName;
     }
-    $display .= COM_siteHeader('menu', $title);
+    $display .= COM_siteHeader('menu', $title, DIR_canonicalLink($topic));
     $display .= DIR_displayAll($topic, $conf_list_current_month);
 }
 



More information about the geeklog-cvs mailing list