[Hastymail-cvs] SF.net SVN: hastymail: [151] trunk/hastymail2
Brought to you by:
sailfrog,
slushpupie
From: <sai...@us...> - 2008-01-31 17:48:24
|
Revision: 151 http://hastymail.svn.sourceforge.net/hastymail/?rev=151&view=rev Author: sailfrog Date: 2008-01-31 09:48:22 -0800 (Thu, 31 Jan 2008) Log Message: ----------- clickable links in text parts is in. This is better than last time, as it does not change the text wrap, and it can handle multiple links on the same line. Unlike in hm1 however rather than replace the link text with an actual <a> link, we put a "link" <a> tag before the unchanged link text with the label "link".. Modified Paths: -------------- trunk/hastymail2/index.php trunk/hastymail2/lib/misc_functions.php trunk/hastymail2/lib/post_action_class.php trunk/hastymail2/lib/site_page_class.php trunk/hastymail2/themes/default/css/site.css Modified: trunk/hastymail2/index.php =================================================================== --- trunk/hastymail2/index.php 2008-01-31 16:33:45 UTC (rev 150) +++ trunk/hastymail2/index.php 2008-01-31 17:48:22 UTC (rev 151) @@ -50,6 +50,7 @@ /* default user settings */ $default_user_settings = array( 'font_family' => 'monospace', + 'text_links' => 0, 'show_folder_list' => 0, 'folder_detail' => 1, 'folder_style' => 1, Modified: trunk/hastymail2/lib/misc_functions.php =================================================================== --- trunk/hastymail2/lib/misc_functions.php 2008-01-31 16:33:45 UTC (rev 150) +++ trunk/hastymail2/lib/misc_functions.php 2008-01-31 17:48:22 UTC (rev 151) @@ -374,6 +374,14 @@ } function prep_text_part($string) { global $user; + global $page_id; + if (isset($_SESSION['user_settings']['text_links']) && $_SESSION['user_settings']['text_links']) { + $links = true; + } + else { + $links = false; + } + $link_regex = "/((http|ftp|rtsp)s?:\/\/(%[[:digit:]A-Fa-f][[:digit:]A-Fa-f]|[-_\.!~\*';\/\?#:@&=\+$,[:alnum:]])+)/i"; if ($user->page_data['raw_view']) { return $string; } @@ -385,23 +393,42 @@ else { $marker = ''; } + $link_inserts = array(); $new_lines = array(); $lines = explode("\r\n", $string); unset($string); + $link_count = 1; while (!empty($lines)) { $split = false; $line = $lines[0]; - if (strlen($line) > $max) { - $first_space = strpos($lines[0], ' ', ($max - 10)); - if ($first_space && $first_space < $max) { + $adjust = 0; + if ($links) { + if (preg_match_all($link_regex, $line, $matches)) { + if (is_array($matches[1])) { + $link_marks = $matches[1]; + } + else { + $link_marks = array($matches[1]); + } + foreach ($link_marks as $v) { + $link_inserts[$link_count] = $v; + $line = str_replace($v, '<link-'.$link_count.'-'.$page_id.'>'.$v, $line); + $link_count++; + $adjust += strlen('<link-'.$link_count.'-'.$page_id.'>'); + } + } + } + if (strlen($line) - $adjust > $max) { + $first_space = strpos($line, ' ', ($max - 10 + $adjust)); + if ($first_space && $first_space < ($max + $adjust)) { $line = substr($line, 0, $first_space); $split = true; } else { - $line = substr($line, 0, $max); + $line = substr($line, 0, ($max + $adjust)); $split = true; } - $lines[0] = ltrim(substr($lines[0], strlen($line))); + $lines[0] = ltrim(substr($lines[0], (strlen($line) - $adjust))); } else { array_shift($lines); @@ -412,7 +439,15 @@ $new_lines[] = str_replace(' " ', '"', $line); $split = false; } - return implode("\n", $new_lines);; + $body = implode("\n", $new_lines); + if ($links) { + foreach ($link_inserts as $i => $v) { + $v = trim($v); + $v = preg_replace("/(\.|\"|>)$/", '', $v); + $body = str_replace('<link-'.$i.'-'.$page_id.'>', '<a href="'.$v.'" title="'.$v.'" target="_blank" class="text_link">link</a> ', $body); + } + } + return $body; } function timer_display($times) { $base = mt_to_num($times['index.php starts']); Modified: trunk/hastymail2/lib/post_action_class.php =================================================================== --- trunk/hastymail2/lib/post_action_class.php 2008-01-31 16:33:45 UTC (rev 150) +++ trunk/hastymail2/lib/post_action_class.php 2008-01-31 17:48:22 UTC (rev 151) @@ -36,6 +36,7 @@ 'font_size' => array('int', 1, 'Font Size'), 'timezone_select' => array('string', 0, 'Timezone'), 'text_wrap' => array('int', 0, 'Wrap text at'), + 'text_links' => array('true', 0, 'Clickable links'), 'show_wrap' => array('true', 0, 'Show wrap marker'), 'mailbox_per_page_count' => array('int_nonzero', 1, 'Messages per page'), 'font_family' => array('string', 1, 'Font Family'), @@ -178,6 +179,10 @@ else { $settings['theme'] = 'default'; } + $settings['text_links'] = 0; + if (isset($post['text_links'])) { + $settings ['text_links'] = true; + } $settings['text_wrap'] = (int) $post['text_wrap']; $mailbox_per_page_count = (int) $post['mailbox_per_page_count']; if ($mailbox_per_page_count > 100) { Modified: trunk/hastymail2/lib/site_page_class.php =================================================================== --- trunk/hastymail2/lib/site_page_class.php 2008-01-31 16:33:45 UTC (rev 150) +++ trunk/hastymail2/lib/site_page_class.php 2008-01-31 17:48:22 UTC (rev 151) @@ -309,7 +309,7 @@ } function print_message_text() { $data = '<div id="message_text" style="font-family: '.$this->pd['settings']['font_family'].';">'; - $data .= $this->user->htmlsafe(prep_text_part($this->pd['message_data']), $this->pd['charset']); + $data .= prep_text_part($this->user->htmlsafe($this->pd['message_data'], $this->pd['charset'])); $data .= '</div>'; return $data; } @@ -711,6 +711,11 @@ $vals = $this->pd['settings']; $font_families = array( 'monospace', 'serif', 'sans-serif', 'cursive', 'fantasy'); $data = '<tr><td class="opt_leftcol">Wrap long lines at</td><td><input name="text_wrap" size="3" type="text" value="'.$vals['text_wrap'].'" /></td></tr>'; + $data .= '<tr><td class="opt_leftcol">Make links clickable in text parts</td><td><input name="text_links" type="checkbox" value="1" '; + if (isset($this->pd['settings']['text_links']) && $this->pd['settings']['text_links']) { + $data .= 'checked="checked" '; + } + $data .= '/></td></tr>'; $data .= '<tr><td class="opt_leftcol">Show line break marker</td><td><input name="show_wrap" type="checkbox" '; if ($vals['show_wrap']) { $data .= 'checked="checked" '; } $data .= 'value="1" /></td></tr>'; Modified: trunk/hastymail2/themes/default/css/site.css =================================================================== --- trunk/hastymail2/themes/default/css/site.css 2008-01-31 16:33:45 UTC (rev 150) +++ trunk/hastymail2/themes/default/css/site.css 2008-01-31 17:48:22 UTC (rev 151) @@ -488,9 +488,10 @@ display: inline; } .opt_leftcol{ + white-space: nowrap; padding-left: 10px; color: #000; - width: 200px; + width: 220px; padding-right: 15px; } #about_images{ @@ -671,3 +672,8 @@ background: #f3f3f3; font-style: italic; } +.text_link{ + font-family: Arial; + font-size: 85%; + font-weight: bold; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |