summaryrefslogtreecommitdiffstats
path: root/lib/class
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 /lib/class
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()
Diffstat (limited to 'lib/class')
-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
6 files changed, 50 insertions, 9 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;
+ }
}