summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Arthur <paul.arthur@flowerysong.com>2013-01-26 01:15:59 -0500
committerPaul Arthur <paul.arthur@flowerysong.com>2013-01-26 01:15:59 -0500
commiteaa44dcd0938ad48f4a9f863b24ca5d3a318ae10 (patch)
tree71d577e01200b3a143971a3a23d8f6b7cdf545fe
parent42133f38d223a2b3b81d309f2d1a983ef2012485 (diff)
downloadampache-eaa44dcd0938ad48f4a9f863b24ca5d3a318ae10.tar.gz
ampache-eaa44dcd0938ad48f4a9f863b24ca5d3a318ae10.tar.bz2
ampache-eaa44dcd0938ad48f4a9f863b24ca5d3a318ae10.zip
Continue moving things into UI
check_php_iconv() from lib/debug.lib.php becomes UI::check_iconv() truncate_with_ellipsis() from lib/ui.lib.php becomes UI::truncate()
-rw-r--r--lib/class/album.class.php4
-rw-r--r--lib/class/artist.class.php2
-rw-r--r--lib/class/catalog.class.php4
-rw-r--r--lib/class/playlist_object.abstract.php2
-rw-r--r--lib/class/song.class.php6
-rw-r--r--lib/class/ui.class.php41
-rw-r--r--lib/debug.lib.php14
-rw-r--r--lib/ui.lib.php34
-rw-r--r--templates/show_install_check.inc.php2
-rw-r--r--templates/show_lyrics_song.inc.php6
-rw-r--r--templates/show_now_playing_row.inc.php2
-rw-r--r--templates/show_test.inc.php2
12 files changed, 56 insertions, 63 deletions
diff --git a/lib/class/album.class.php b/lib/class/album.class.php
index 16ef541d..c7b88dcf 100644
--- a/lib/class/album.class.php
+++ b/lib/class/album.class.php
@@ -240,7 +240,7 @@ class Album extends database_object {
foreach ($data as $key=>$value) { $this->$key = $value; }
/* Truncate the string if it's to long */
- $this->f_name = truncate_with_ellipsis($this->full_name,Config::get('ellipse_threshold_album'));
+ $this->f_name = UI::truncate($this->full_name,Config::get('ellipse_threshold_album'));
$this->f_name_link = "<a href=\"$web_path/albums.php?action=show&amp;album=" . scrub_out($this->id) . "\" title=\"" . scrub_out($this->full_name) . "\">" . scrub_out($this->f_name);
// If we've got a disk append it
@@ -254,7 +254,7 @@ class Album extends database_object {
if ($this->artist_count == '1') {
$artist = trim(trim($this->artist_prefix) . ' ' . trim($this->artist_name));
$this->f_artist_name = $artist;
- $artist = scrub_out(truncate_with_ellipsis($artist), Config::get('ellipse_threshold_artist'));
+ $artist = scrub_out(UI::truncate($artist), Config::get('ellipse_threshold_artist'));
$this->f_artist_link = "<a href=\"$web_path/artists.php?action=show&amp;artist=" . $this->artist_id . "\" title=\"" . scrub_out($this->artist_name) . "\">" . $artist . "</a>";
$this->f_artist = $artist;
}
diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php
index d4e2df76..d971e33a 100644
--- a/lib/class/artist.class.php
+++ b/lib/class/artist.class.php
@@ -241,7 +241,7 @@ class Artist extends database_object {
public function format() {
/* Combine prefix and name, trim then add ... if needed */
- $name = truncate_with_ellipsis(trim($this->prefix . " " . $this->name),Config::get('ellipse_threshold_artist'));
+ $name = UI::truncate(trim($this->prefix . " " . $this->name),Config::get('ellipse_threshold_artist'));
$this->f_name = $name;
$this->f_full_name = trim(trim($this->prefix) . ' ' . trim($this->name));
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php
index ac83feb2..029c2d67 100644
--- a/lib/class/catalog.class.php
+++ b/lib/class/catalog.class.php
@@ -144,9 +144,9 @@ class Catalog extends database_object {
*/
public function format() {
- $this->f_name = truncate_with_ellipsis($this->name,Config::get('ellipse_threshold_title'));
+ $this->f_name = UI::truncate($this->name,Config::get('ellipse_threshold_title'));
$this->f_name_link = '<a href="' . Config::get('web_path') . '/admin/catalog.php?action=show_customize_catalog&catalog_id=' . $this->id . '" title="' . scrub_out($this->name) . '">' . scrub_out($this->f_name) . '</a>';
- $this->f_path = truncate_with_ellipsis($this->path,Config::get('ellipse_threshold_title'));
+ $this->f_path = UI::truncate($this->path,Config::get('ellipse_threshold_title'));
$this->f_update = $this->last_update ? date('d/m/Y h:i',$this->last_update) : T_('Never');
$this->f_add = $this->last_add ? date('d/m/Y h:i',$this->last_add) : T_('Never');
$this->f_clean = $this->last_clean ? date('d/m/Y h:i',$this->last_clean) : T_('Never');
diff --git a/lib/class/playlist_object.abstract.php b/lib/class/playlist_object.abstract.php
index 659cb337..48eefb0d 100644
--- a/lib/class/playlist_object.abstract.php
+++ b/lib/class/playlist_object.abstract.php
@@ -39,7 +39,7 @@ abstract class playlist_object extends database_object {
*/
public function format() {
- $this->f_name = truncate_with_ellipsis($this->name,Config::get('ellipse_threshold_title'));
+ $this->f_name = UI::truncate($this->name,Config::get('ellipse_threshold_title'));
$this->f_type = ($this->type == 'private') ? get_user_icon('lock', T_('Private')) : '';
$client = new User($this->user);
diff --git a/lib/class/song.class.php b/lib/class/song.class.php
index 88c1b270..b547f71a 100644
--- a/lib/class/song.class.php
+++ b/lib/class/song.class.php
@@ -761,15 +761,15 @@ class Song extends database_object implements media {
// Format the album name
$this->f_album_full = $this->get_album_name();
- $this->f_album = truncate_with_ellipsis($this->f_album_full,Config::get('ellipse_threshold_album'));
+ $this->f_album = UI::truncate($this->f_album_full,Config::get('ellipse_threshold_album'));
// Format the artist name
$this->f_artist_full = $this->get_artist_name();
- $this->f_artist = truncate_with_ellipsis($this->f_artist_full,Config::get('ellipse_threshold_artist'));
+ $this->f_artist = UI::truncate($this->f_artist_full,Config::get('ellipse_threshold_artist'));
// Format the title
$this->f_title_full = $this->title;
- $this->f_title = truncate_with_ellipsis($this->title,Config::get('ellipse_threshold_title'));
+ $this->f_title = UI::truncate($this->title,Config::get('ellipse_threshold_title'));
// Create Links for the different objects
$this->link = Config::get('web_path') . "/song.php?action=show_song&song_id=" . $this->id;
diff --git a/lib/class/ui.class.php b/lib/class/ui.class.php
index 7a56d2d7..e47fe0d1 100644
--- a/lib/class/ui.class.php
+++ b/lib/class/ui.class.php
@@ -46,6 +46,18 @@ class UI {
}
/**
+ * check_iconv
+ *
+ * Checks to see whether iconv is available;
+ */
+ public static function check_iconv() {
+ if (function_exists('iconv') && function_exists('iconv_substr')) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
* check_ticker
*
* Stupid little cutesie thing to ratelimit output of long-running
@@ -75,4 +87,33 @@ class UI {
}
return self::$_classes[0];
}
+
+ /**
+ * truncate
+ *
+ * Limit text to a certain length; adds an ellipsis if truncation was
+ * required.
+ */
+ public static function truncate($text, $max = 27) {
+ // If they want <3, we're having none of that
+ if ($max <= 3) {
+ debug_event('UI', "truncate called with $max, refusing to do stupid things to $text", 2);
+ return $text;
+ }
+
+ if (self::check_iconv()) {
+ $charset = Config::get('site_charset');
+ if (iconv_strlen($text, $charset) > $max) {
+ $text = iconv_substr($text, 0, $max - 3, $charset);
+ $text .= iconv('ISO-8859-1', $charset, '...');
+ }
+ }
+ else {
+ if (strlen($text) > $max) {
+ $text = substr($text, 0, $max - 3) . '...';
+ }
+ }
+
+ return $text;
+ }
}
diff --git a/lib/debug.lib.php b/lib/debug.lib.php
index 465801a7..8087bf4d 100644
--- a/lib/debug.lib.php
+++ b/lib/debug.lib.php
@@ -73,20 +73,6 @@ function check_php_session() {
} // check_php_session
/**
- * check_php_iconv
- * checks to see if you have iconv installed
- */
-function check_php_iconv() {
-
- if (!function_exists('iconv')) {
- return false;
- }
-
- return true;
-
-} // check_php_iconv
-
-/**
* check_php_pcre
* This makes sure they have pcre (preg_???) support
* compiled into PHP this is required!
diff --git a/lib/ui.lib.php b/lib/ui.lib.php
index f767c55b..72b87f45 100644
--- a/lib/ui.lib.php
+++ b/lib/ui.lib.php
@@ -75,40 +75,6 @@ function return_referer() {
} // return_referer
/**
- * truncate_with_ellipsis
- * Function that truncates text to a specific length and appends an ellipsis to
- * the end.
- */
-function truncate_with_ellipsis($text, $max='') {
-
- $max = $max ? $max : '27';
-
- /* If they want it to be shorter than three, just throw it back */
- if ($max <= 3) {
- return $text;
- }
-
- /* Make sure the functions exist before doing the iconv mojo */
- if (function_exists('iconv') &&
- function_exists('iconv_substr') &&
- function_exists('iconv_strlen')) {
- $charset = Config::get('site_charset');
- if (iconv_strlen($text, $charset) > $max) {
- $text = iconv_substr($text, 0, $max-3, $charset);
- $text .= iconv("ISO-8859-1", $charset, "...");
- }
- }
- else { // Use normal substr if we don't have iconv
- if (strlen($text) > $max) {
- $text = substr($text,0,$max-3)."...";
- }
- } // else no iconv
-
- return $text;
-
-} // truncate_with_ellipsis
-
-/**
* show_header
* This shows the header.inc.php, it may do something
* more in the future
diff --git a/templates/show_install_check.inc.php b/templates/show_install_check.inc.php
index 6ff093c9..9cd719a8 100644
--- a/templates/show_install_check.inc.php
+++ b/templates/show_install_check.inc.php
@@ -102,7 +102,7 @@
<td><?php echo T_('PHP iconv Support'); ?>:</td>
<td>
<?php
- if (!check_php_iconv()) {
+ if (!UI::check_iconv()) {
echo debug_result('',false);
Error::add('install', T_('PHP iconv Support'));
}
diff --git a/templates/show_lyrics_song.inc.php b/templates/show_lyrics_song.inc.php
index 74f67b2d..677f1517 100644
--- a/templates/show_lyrics_song.inc.php
+++ b/templates/show_lyrics_song.inc.php
@@ -23,9 +23,9 @@
show_box_top($song->title , 'box box_lyrics_song');
/* Prepare the variables */
-$title = scrub_out(truncate_with_ellipsis($song->title));
-$album = scrub_out(truncate_with_ellipsis($song->f_album_full));
-$artist = scrub_out(truncate_with_ellipsis($song->f_artist_full));
+$title = scrub_out(UI::truncate($song->title));
+$album = scrub_out(UI::truncate($song->f_album_full));
+$artist = scrub_out(UI::truncate($song->f_artist_full));
?>
<div class="np_group">
<?php if (Config::get('show_album_art')) { ?>
diff --git a/templates/show_now_playing_row.inc.php b/templates/show_now_playing_row.inc.php
index fc7f7681..30553a8d 100644
--- a/templates/show_now_playing_row.inc.php
+++ b/templates/show_now_playing_row.inc.php
@@ -81,7 +81,7 @@
<div class="np_cel cel_similar_artist">
<?php
if (is_null($a['id'])) {
- echo scrub_out(truncate_with_ellipsis($a['name']), Config::get('ellipse_threshold_artist'));
+ echo scrub_out(UI::truncate($a['name']), Config::get('ellipse_threshold_artist'));
}
else {
$artist = new Artist($a['id']);
diff --git a/templates/show_test.inc.php b/templates/show_test.inc.php
index 09eee209..c9453a2c 100644
--- a/templates/show_test.inc.php
+++ b/templates/show_test.inc.php
@@ -99,7 +99,7 @@
<td valign="top"><?php echo T_('PHP iconv extension'); ?></td>
<td valign="top">[
<?php
- if (!check_php_iconv()) {
+ if (!UI::check_iconv()) {
echo debug_result('',false);
}
else {