summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-rw-r--r--system/helpers/text_helper.php105
-rw-r--r--system/language/english/ftp_lang.php1
-rw-r--r--system/libraries/Email.php107
3 files changed, 138 insertions, 75 deletions
diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php
index fbc63a9b4..1b9178129 100644
--- a/system/helpers/text_helper.php
+++ b/system/helpers/text_helper.php
@@ -325,62 +325,97 @@ function highlight_phrase($str, $phrase, $tag_open = '<strong>', $tag_close = '<
* Word Wrap
*
* Wraps text at the specified character. Maintains the integrity of words.
+ * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor
+ * will URLs.
*
* @access public
* @param string the text string
* @param integer the number of characters to wrap at
* @return string
*/
-function word_wrap($str, $chars = '76')
-{
- if ( ! is_numeric($chars))
- $chars = 76;
+function word_wrap($str, $charlim = '76')
+{
+ // Se the character limit
+ if ( ! is_numeric($charlim))
+ $charlim = 76;
+
+ // Reduce multiple spaces
+ $str = preg_replace("| +|", " ", $str);
- $str = preg_replace("/(\r\n|\r|\n)/", "\n", $str);
- $lines = split("\n", $str);
+ // Standardize newlines
+ $str = preg_replace("/\r\n|\r/", "\n", $str);
+ // If the current word is surrounded by {unwrap} tags we'll
+ // strip the entire chunk and replace it with a marker.
+ $unwrap = array();
+ if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches))
+ {
+ for ($i = 0; $i < count($matches['0']); $i++)
+ {
+ $unwrap[] = $matches['1'][$i];
+ $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str);
+ }
+ }
+
+ // Use PHP's native function to do the initial wordwrap.
+ // We set the cut flag to FALSE so that any individual words that are
+ // too long get left alone. In the next step we'll deal with them.
+ $str = wordwrap($str, $charlim, "\n", FALSE);
+
+ // Split the string into individual lines of text and cycle through them
$output = "";
- while (list(, $thisline) = each($lines))
+ foreach (explode("\n", $str) as $line)
{
- if (strlen($thisline) > $chars)
+ // Is the line within the allowed character count?
+ // If so we'll join it to the output and continue
+ if (strlen($line) <= $charlim)
+ {
+ $output .= $line.$this->newline;
+ continue;
+ }
+
+ $temp = '';
+ while((strlen($line)) > $charlim)
{
- $line = "";
- $words = split(" ", $thisline);
- while(list(, $thisword) = each($words))
+ // If the over-length word is a URL we won't wrap it
+ if (preg_match("!\[url.+\]|://|wwww.!", $line))
{
- while((strlen($thisword)) > $chars)
- {
- $cur_pos = 0;
- for($i=0; $i < $chars - 1; $i++)
- {
- $output .= $thisword[$i];
- $cur_pos++;
- }
-
- $output .= "\n";
- $thisword = substr($thisword, $cur_pos, (strlen($thisword) - $cur_pos));
- }
-
- if ((strlen($line) + strlen($thisword)) > $chars)
- {
- $output .= $line."\n";
- $line = $thisword." ";
- }
- else
- {
- $line .= $thisword." ";
- }
+ break;
}
- $output .= $line."\n";
+ // Trim the word down
+ $temp .= substr($line, 0, $charlim-1);
+ $line = substr($line, $charlim-1);
+ }
+
+ // If $temp contains data it means we had to split up an over-length
+ // word into smaller chunks so we'll add it back to our current line
+ if ($temp != '')
+ {
+ $output .= $temp.$this->newline.$line;
}
else
{
- $output .= $thisline."\n";
+ $output .= $line;
+ }
+
+ $output .= $this->newline;
+ }
+
+ // Put our markers back
+ if (count($unwrap) > 0)
+ {
+ foreach ($unwrap as $key => $val)
+ {
+ $output = str_replace("{{unwrapped".$key."}}", $val, $output);
}
}
+ // Remove the unwrap tags
+ $output = str_replace(array('{unwrap}', '{/unwrap}'), '', $output);
+
return $output;
}
+
?> \ No newline at end of file
diff --git a/system/language/english/ftp_lang.php b/system/language/english/ftp_lang.php
index 99895cc0a..d6a1a40cf 100644
--- a/system/language/english/ftp_lang.php
+++ b/system/language/english/ftp_lang.php
@@ -1,5 +1,6 @@
<?php
+$lang['ftp_no_connection'] = "Unable to locate a valid connection ID. Please make sure you are connected before peforming any file routines.";
$lang['ftp_unable_to_connect'] = "Unable to connect to your FTP server using the supplied hostname.";
$lang['ftp_unable_to_login'] = "Unable to login to your FTP server. Please check your username and password.";
$lang['ftp_unable_to_makdir'] = "Unable to create the directory you have specified.";
diff --git a/system/libraries/Email.php b/system/libraries/Email.php
index 158c82af2..e6dd614f4 100644
--- a/system/libraries/Email.php
+++ b/system/libraries/Email.php
@@ -748,56 +748,83 @@ class CI_Email {
* @param integer
* @return string
*/
- function word_wrap($str, $chars = '')
- {
- if ($chars == '')
+ function word_wrap($str, $charlim = '')
+ {
+ // Se the character limit
+ if ($charlim == '')
{
- $chars = ($this->wrapchars == "") ? "76" : $this->wrapchars;
+ $charlim = ($this->wrapchars == "") ? "76" : $this->wrapchars;
}
+ // Reduce multiple spaces
$str = preg_replace("| +|", " ", $str);
-
- $str = preg_replace("|(\[url.+\])|", "{unwrap}\\1{/unwrap}", $str);
-
+
+ // Standardize newlines
+ $str = preg_replace("/\r\n|\r/", "\n", $str);
+
+ // If the current word is surrounded by {unwrap} tags we'll
+ // strip the entire chunk and replace it with a marker.
+ $unwrap = array();
+ if (preg_match_all("|(\{unwrap\}.+?\{/unwrap\})|s", $str, $matches))
+ {
+ for ($i = 0; $i < count($matches['0']); $i++)
+ {
+ $unwrap[] = $matches['1'][$i];
+ $str = str_replace($matches['1'][$i], "{{unwrapped".$i."}}", $str);
+ }
+ }
+
+ // Use PHP's native function to do the initial wordwrap.
+ // We set the cut flag to FALSE so that any individual words that are
+ // too long get left alone. In the next step we'll deal with them.
+ $str = wordwrap($str, $charlim, "\n", FALSE);
+
+ // Split the string into individual lines of text and cycle through them
$output = "";
- foreach (split("\n", $str) as $current_line)
+ foreach (explode("\n", $str) as $line)
{
- if (strlen($current_line) > $chars)
+ // Is the line within the allowed character count?
+ // If so we'll join it to the output and continue
+ if (strlen($line) <= $charlim)
{
- $line = "";
-
- foreach (split(" ", $current_line) as $words)
+ $output .= $line.$this->newline;
+ continue;
+ }
+
+ $temp = '';
+ while((strlen($line)) > $charlim)
+ {
+ // If the over-length word is a URL we won't wrap it
+ if (preg_match("!\[url.+\]|://|wwww.!", $line))
{
- while((strlen($words)) > $chars)
- {
- if (stristr($words, '{unwrap}') !== FALSE OR stristr($words, '{/unwrap}') !== FALSE)
- {
- break;
- }
-
- $output .= substr($words, 0, $chars-1);
- $words = substr($words, $chars-1);
-
- $output .= $this->newline;
- }
-
- if ((strlen($line) + strlen($words)) > $chars)
- {
- $output .= $line.$this->newline;
-
- $line = $words." ";
- }
- else
- {
- $line .= $words." ";
- }
+ break;
}
-
- $output .= $line.$this->newline;
- }
- else
+
+ // Trim the word down
+ $temp .= substr($line, 0, $charlim-1);
+ $line = substr($line, $charlim-1);
+ }
+
+ // If $temp contains data it means we had to split up an over-length
+ // word into smaller chunks so we'll add it back to our current line
+ if ($temp != '')
+ {
+ $output .= $temp.$this->newline.$line;
+ }
+ else
+ {
+ $output .= $line;
+ }
+
+ $output .= $this->newline;
+ }
+
+ // Put our markers back
+ if (count($unwrap) > 0)
+ {
+ foreach ($unwrap as $key => $val)
{
- $output .= $current_line.$this->newline;
+ $output = str_replace("{{unwrapped".$key."}}", $val, $output);
}
}