cvs: docweb /include lib_url_entities.inc.php /templates/all/www checkent.tpl.php

From: Date: Tue, 25 Jan 2005 20:05:18 +0000
Subject: cvs: docweb /include lib_url_entities.inc.php /templates/all/www checkent.tpl.php
Groups: php.doc.web 
Request: Send a blank email to doc-web+get-570@lists.php.net to get a copy of this message
sean Tue Jan 25 15:05:18 2005 EDT Modified files: /docweb/include lib_url_entities.inc.php /docweb/templates/all/www checkent.tpl.php Log: chopped URLs in non-wide mode (http://url..istoolong/) http://cvs.php.net/diff.php/docweb/include/lib_url_entities.inc.php?r1=1.9&r2=1.10&ty=u Index: docweb/include/lib_url_entities.inc.php diff -u docweb/include/lib_url_entities.inc.php:1.9 docweb/include/lib_url_entities.inc.php:1.10 --- docweb/include/lib_url_entities.inc.php:1.9 Tue Jan 25 14:37:48 2005 +++ docweb/include/lib_url_entities.inc.php Tue Jan 25 15:05:17 2005 @@ -19,7 +19,7 @@ | Mehdi Achour <didou@php.net> | | Sean Coates <sean@php.net> | +----------------------------------------------------------------------+ -$Id: lib_url_entities.inc.php,v 1.9 2005/01/25 19:37:48 nlopess Exp $ +$Id: lib_url_entities.inc.php,v 1.10 2005/01/25 20:05:17 sean Exp $ */ // user agent @@ -321,7 +321,52 @@ function ent_link($eVal) { - return preg_replace('/&([^;]+);/', '<a href="entities.php#ent-\1">&amp;\1;</a>', $eVal); +return preg_replace('/&([^;]+);/', '<a href="entities.php#ent-\1">&amp;\1;</a>', $eVal); } +/** + * Chop a string into a smaller string + * "Public Domain" code from: http://aidan.dotgeek.org/lib/?file=function.str_chop.php + * + * @author Aidan Lister <aidan@php.net> + * @version 1.1 + * @param mixed $string The string you want to shorten + * @param int $length The length you want to shorten the string to + * @param bool $center If true, chop in the middle of the string + * @param mixed $append String appended if it is shortened + */ +function str_chop($string, $length = 60, $center = false, $append = null) +{ + // Set the default append string + if ($append === null) { + $append = ($center === true) ? ' ... ' : ' ...'; + } + + // Get some measurements + $len_string = strlen($string); + $len_append = strlen($append); + + // If the string is longer than the maximum length, we need to chop it + if ($len_string > $length) { + // Check if we want to chop it in half + if ($center === true) { + // Get the lengths of each segment + $len_start = $length / 2; + $len_end = $len_start - $len_append; + + // Get each segment + $seg_start = substr($string, 0, $len_start); + $seg_end = substr($string, $len_string - $len_end, $len_end); + + // Stick them together + $string = $seg_start . $append . $seg_end; + } else { + // Otherwise, just chop the end off + $string = substr($string, 0, $length - $len_append) . $append; + } + } + + return $string; +} + ?> http://cvs.php.net/diff.php/docweb/templates/all/www/checkent.tpl.php?r1=1.4&r2=1.5&ty=u Index: docweb/templates/all/www/checkent.tpl.php diff -u docweb/templates/all/www/checkent.tpl.php:1.4 docweb/templates/all/www/checkent.tpl.php:1.5 --- docweb/templates/all/www/checkent.tpl.php:1.4 Tue Jan 25 14:47:36 2005 +++ docweb/templates/all/www/checkent.tpl.php Tue Jan 25 15:05:18 2005 @@ -2,7 +2,6 @@ /* TODO: - language-entity this - - Shrink long URLs: http://example.org/this/is/a...long/url */ if ($isComplete) { ?> @@ -38,13 +37,26 @@ <?php if ($wideMode) { ?> <td><?php echo $r['entity']; ?></td> <td><a href="<?php echo $r['url']; ?>" rel="nofollow"><?php echo $r['url']; ?></a></td> + <td><a href="<?php echo $r['return_val']; ?>" rel="nofollow"><?php echo $r['return_val']; ?></a></td> <?php } else { ?> <td><a href="<?php echo $r['url']; ?>"><?php echo $r['entity']; ?></a></td> + <td> + <a href="<?php echo $r['return_val']; ?>" rel="nofollow" title="<?php echo $r['return_val']; ?>"> + <?php echo str_chop($r['return_val'], 60, TRUE); ?> + </a> + </td> <?php } ?> - <td><a href="<?php echo $r['return_val']; ?>" rel="nofollow"><?php echo $r['return_val']; ?></a></td> <?php } else { ?> <td><?php echo $r['entity']; ?></td> - <td><a href="<?php echo $r['url']; ?>" rel="nofollow"><?php echo $r['url']; ?></a></td> + <?php if ($wideMode) { ?> + <td><a href="<?php echo $r['url']; ?>" rel="nofollow"><?php echo $r['url']; ?></a></td> + <?php } else { ?> + <td> + <a href="<?php echo $r['url']; ?>" rel="nofollow" title="<?php echo $r['url']; ?>"> + <?php echo str_chop($r['url'], 60, TRUE); ?> + </a> + </td> + <?php } ?> <?php } ?> </tr> <?php } ?>

« previous php.doc.web (#570) next »