From: Vishesh Duggar <vishesh@greenferretllc.com>
Date: Wed, 26 Jan 2011 13:40:43 -0500
Subject: [PATCH] adding feature to gcal_events. Adding a template variable called #TRUNCATEDTITLE#
 And a setting that will let user specify number of characters after which to truncate the title.
 Original title will still be available through #TITLE#

---
 .../contributed/gcal_events/gcal_events.module     |   26 +++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/all/modules/contributed/gcal_events/gcal_events.module b/all/modules/contributed/gcal_events/gcal_events.module
index 1698b8d..09fcc22 100755
--- a/all/modules/contributed/gcal_events/gcal_events.module
+++ b/all/modules/contributed/gcal_events/gcal_events.module
@@ -29,6 +29,8 @@ else {
  */
 define('GCAL_EVENTS_DEFAULT_TEMPLATE_EVENT', '<P>#TITLE##LOC##DATE##TIME#');
 define('GCAL_EVENTS_DEFAULT_TEMPLATE_TITLE', '<b>#TITLE#</b><br>');
+define('GCAL_EVENTS_DEFAULT_TEMPLATE_TRUNCATED_TITLE', '<b>#TRUNCATEDTITLE#</b><br>');
+define('GCAL_EVENTS_DEFAULT_TEMPLATE_TITLE_LENGTH', 0);
 define('GCAL_EVENTS_DEFAULT_TEMPLATE_DATE', '#DATE#<br>');
 define('GCAL_EVENTS_DEFAULT_TEMPLATE_TIME', '#TIME#<br>');
 define('GCAL_EVENTS_DEFAULT_TEMPLATE_DESC', '#DESC#<br>');
@@ -315,7 +317,7 @@ function gcal_events_block($op = 'list', $delta = 0, $edit = array()) {
         '#type' => 'fieldset',
 	'#title' => t('Templates'),
 	'#collapsible' => TRUE,
-	'#description' => t('These are the templates to use. Variables #TITLE#, #DESC#, #DATE#, #TIME#, #LOC#, #URL#, and #LOCURL# are availble for use. It is recommended to only use multiple variables inside the event template.')
+	'#description' => t('These are the templates to use. Variables #TITLE#,#TRUNCATEDTITLE#, #DESC#, #DATE#, #TIME#, #LOC#, #URL#, and #LOCURL# are availble for use. It is recommended to only use multiple variables inside the event template.')
 	);
 
       $form['template']['gcal_events_template_event'] = array(
@@ -332,6 +334,18 @@ function gcal_events_block($op = 'list', $delta = 0, $edit = array()) {
         '#description' => t('Use #TITLE# to insert the title.'),
         '#default_value' => variable_get('gcal_events_template_title_'. $delta, GCAL_EVENTS_DEFAULT_TEMPLATE_TITLE)
         );
+        $form['template']['gcal_events_template_title_length'] = array(
+        '#type' => 'textfield',
+        '#title' => 'Title Length',
+        '#description' => t('Specify a number of characters after which the title should be truncated. This truncated title is available through #TRUNCATEDTITLE# in the template'),
+        '#default_value' => variable_get('gcal_events_template_title_length_'. $delta, GCAL_EVENTS_DEFAULT_TEMPLATE_TITLE_LENGTH)
+        );
+        $form['template']['gcal_events_template_truncated_title'] = array(
+        '#type' => 'textfield',
+        '#title' => 'Truncated Title Template (#TRUNCATEDTITLE#)',
+        '#description' => t('Use #TRUNCATEDTITLE# to insert the title.'),
+        '#default_value' => variable_get('gcal_events_template_truncated_title_'. $delta, GCAL_EVENTS_DEFAULT_TEMPLATE_TRUNCATED_TITLE)
+        );
       $form['template']['gcal_events_template_desc'] = array(
         '#type' => 'textfield',
         '#title' => 'Description Template (#DESC#)',
@@ -416,6 +430,8 @@ function gcal_events_block($op = 'list', $delta = 0, $edit = array()) {
       variable_set('gcal_events_admin_name_'. $delta, check_plain($edit['gcal_events_admin_name']));
       variable_set('gcal_events_template_event_'. $delta, $edit['gcal_events_template_event'], 'gcal_events' );
       variable_set('gcal_events_template_title_'. $delta, $edit['gcal_events_template_title']);
+      variable_set('gcal_events_template_truncated_title_'. $delta, $edit['gcal_events_template_truncated_title']);
+      variable_set('gcal_events_template_title_length_'. $delta, $edit['gcal_events_template_title_length']);
       variable_set('gcal_events_template_desc_'. $delta, $edit['gcal_events_template_desc']);
       variable_set('gcal_events_template_time_'. $delta, $edit['gcal_events_template_time']);
       variable_set('gcal_events_template_date_'. $delta, $edit['gcal_events_template_date']);
@@ -453,6 +469,7 @@ function block_reset_defaults($form, &$form_state) {
   variable_del('gcal_events_timeformat_'. $block_number);
   variable_del('gcal_events_template_event_'. $block_number);
   variable_del('gcal_events_template_title_'. $block_number);
+  variable_del('gcal_events_template_title_length_'. $block_number);
   variable_del('gcal_events_template_desc_'. $block_number);
   variable_del('gcal_events_template_date_'. $block_number);
   variable_del('gcal_events_template_time_'. $block_number);
@@ -688,8 +705,15 @@ function gcal_events_contents($which_block) {
 
     // Now, let's run it through some str_replaces, and store it with the date for easy sorting later
     $temp_event=variable_get('gcal_events_template_event_'. $which_block, GCAL_EVENTS_DEFAULT_TEMPLATE_EVENT);
+    // Let us load the length of the title after which it should be truncated
+    $title_length = variable_get('gcal_events_template_title_length_'. $which_block, GCAL_EVENTS_DEFAULT_TEMPLATE_TITLE_LENGTH);
 
     if ($item['title']) {
+      $temp_truncated_title = $item['title']; // incase no truncation happens use the original title
+      if(strlen($item['title'])>$title_length && $title_length!=0){
+      	$temp_truncated_title = substr($item['title'],0,$title_length-2)."...";      	
+      }
+      $temp_event=str_replace("#TRUNCATEDTITLE#", $temp_truncated_title, str_replace("#TRUNCATEDTITLE#", variable_get('gcal_events_template_truncated_title_'. $which_block, GCAL_EVENTS_DEFAULT_TEMPLATE_TRUNCATED_TITLE), $temp_event));
       $temp_event=str_replace("#TITLE#", $item['title'], str_replace("#TITLE#", variable_get('gcal_events_template_title_'. $which_block, GCAL_EVENTS_DEFAULT_TEMPLATE_TITLE), $temp_event));
     }
     else {
-- 
1.7.3.4

