瀏覽代碼

Strip HTML for hyperlink creation from core

pdontthink 18 年之前
父節點
當前提交
8245571b10
共有 4 個文件被更改,包括 49 次插入11 次删除
  1. 5 5
      functions/page_header.php
  2. 6 2
      functions/strings.php
  3. 6 4
      plugins/listcommands/functions.php
  4. 32 0
      templates/default/hyperlink.tpl

+ 5 - 5
functions/page_header.php

@@ -147,11 +147,8 @@ EOS;
  * @param string target the target frame for this link
  */
 function makeInternalLink($path, $text, $target='') {
-    global $base_uri;
+    global $base_uri, $oTemplate;
 //    sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
-    if ($target != '') {
-        $target = " target=\"$target\"";
-    }
 
     // This is an inefficient hook and is only used by
     // one plugin that still needs to patch this code,
@@ -162,7 +159,10 @@ function makeInternalLink($path, $text, $target='') {
     //
     //do_hook('internal_link', $text);
 
-    return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
+    $oTemplate->assign('uri', $base_uri . $path);
+    $oTemplate->assign('text', $text);
+    $oTemplate->assign('target', $target);
+    return $oTemplate->fetch('hyperlink.tpl');
 }
 
 /**

+ 6 - 2
functions/strings.php

@@ -792,7 +792,8 @@ function quoteimap($str) {
  * @since 1.4.2
  */
 function makeComposeLink($url, $text = null, $target='') {
-    global $compose_new_win,$javascript_on, $compose_width, $compose_height;
+    global $compose_new_win, $javascript_on, $compose_width, 
+           $compose_height, $oTemplate;
 
     if(!$text) {
         $text = _("Compose");
@@ -811,7 +812,10 @@ function makeComposeLink($url, $text = null, $target='') {
     if($javascript_on) {
         sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
         $compuri = SM_BASE_URI.$url;
-        return "<a href=\"javascript:void(0)\" onclick=\"comp_in_new('$compuri','$compose_width','$compose_height')\">$text</a>";
+        $oTemplate->assign('uri', 'javascript:void(0)');
+        $oTemplate->assign('text', $text);
+        $oTemplate->assign('onclick', "comp_in_new('$compuri','$compose_width','$compose_height')");
+        return $oTemplate->fetch('hyperlink.tpl');
     }
 
     // otherwise, just open new window using regular HTML

+ 6 - 4
plugins/listcommands/functions.php

@@ -19,7 +19,7 @@
  * internal function that builds mailing list links
  */
 function plugin_listcommands_menu_do() {
-    global $passed_id, $passed_ent_id, $color, $mailbox, $message, $startMessage;
+    global $passed_id, $passed_ent_id, $color, $mailbox, $message, $startMessage, $oTemplate;
 
     /**
      * Array of commands we can deal with from the header. The Reply option
@@ -63,13 +63,15 @@ function plugin_listcommands_menu_do() {
                 $links[] = makeComposeLink($url, $fieldsdescr['reply']);
             }
         } else if ($proto == 'href') {
-            $links[] = '<a href="' . $act . '" target="_blank">'
-                . $fieldsdescr[$cmd] . '</a>';
+            $oTemplate->assign('uri', $act);
+            $oTemplate->assign('target', '_blank');
+            $oTemplate->assign('text', $fieldsdescr[$cmd]);
+            $output = $oTemplate->fetch('hyperlink.tpl');
+            $links[] = $output;
         }
     }
 
     if (count($links) > 0) {
-        global $oTemplate;
         $oTemplate->assign('links', $links);
         $output = $oTemplate->fetch('plugins/listcommands/read_body_header.tpl');
         return array('read_body_header' => $output);

+ 32 - 0
templates/default/hyperlink.tpl

@@ -0,0 +1,32 @@
+<?php
+
+/**
+  * hyperlink.tpl
+  *
+  * Template for constructing a hyperlink.
+  *
+  * The following variables are available in this template:
+  *      + $uri     - the target link location
+  *      + $text    - link text
+  *      + $target  - the location where the link should be opened 
+  *                   (optional; may not be present)
+  *      + $onclick - onClick JavaScript handler (optional; may not be present)
+  *      + $extra   - any extra text to be directly inserted into the hyperlink
+  *                   (note to core developers - PLEASE AVOID using this, as it
+  *                   usually means you are adding template-engine specific output
+  *                   to the core)
+  *
+  * @copyright &copy; 1999-2006 The SquirrelMail Project Team
+  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+  * @version $Id$
+  * @package squirrelmail
+  * @subpackage plugins
+  */
+
+
+// retrieve the template vars
+//
+extract($t);
+
+
+?><a href="<?php echo $uri ?>"<?php if (!empty($target)) echo ' target="' . $target . '"'; ?><?php if (!empty($onclick)) echo ' onclick="' . $onclick . '"'; ?>><?php echo $text; ?></a>